GeezerVison is showing github.com — Avoid FileReader · Issue #1537 · googleapis/google-cloud-java
DescriptionNoticed you're using FileReader in com.google.cloud.ServiceOptions and possibly elsewhere. This is potentially buggy because it depends on the platform default encoding and thus behavior can change from one system to the next. Instead, try an InputStreamReader with a specified encoding chained to a FileInputStream.
protected static String googleCloudProjectId() {
File configDir;
if (System.getenv().containsKey("CLOUDSDK_CONFIG")) {
configDir = new File(System.getenv("CLOUDSDK_CONFIG"));
} else if (isWindows() && System.getenv().containsKey("APPDATA")) {
configDir = new File(System.getenv("APPDATA"), "gcloud");
} else {
configDir = new File(System.getProperty("user.home"), ".config/gcloud");
}
String activeConfig = activeGoogleCloudConfig(configDir);
FileReader fileReader = null;
try {
fileReader = new FileReader(new File(configDir, "configurations/config_" + activeConfig));
} catch (FileNotFoundException newConfigFileNotFoundEx) {
try {
fileReader = new FileReader(new File(configDir, "properties"));
} catch (FileNotFoundException oldConfigFileNotFoundEx) {
// ignore
}
}
Activityadded type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns. priority: p2Moderately-important priority. Fix may not be included in next release. on May 24, 2017garrettjonesgoogle commented on Aug 10, 2017 @elharo Do we know that the encoding of the configuration files will always be the same? elharo commented on Aug 10, 2017 ContributorAuthor More actions The problem is that you can't assume it is the native encoding of the platform. I.e. there is no guarantee that FileReader() does the right thing.
You'd have to ask gcloud what character set they use. added and removed type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns. on Nov 9, 2017yihanzhen commented on Jan 11, 2018 The feature request is added to the backlog. The issue will be closed but is linked in the backlog and can continue to be used for comment and discussion.
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|