aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/packages
diff options
context:
space:
mode:
authorGravatar Jingwen Chen <jingwen@google.com>2018-05-11 08:56:06 -0700
committerGravatar Copybara-Service <copybara-piper@google.com>2018-05-11 08:57:16 -0700
commit91b867f6b1b5c417172efe1fa278282d14500922 (patch)
tree01bdfc404a15169ace91521e9866bbdce422b737 /src/main/java/com/google/devtools/build/lib/packages
parenta8ddd36c3a68d9c58357399f349fd70a14d79d92 (diff)
Set Locale to English when uppercasing strings to match Enums
Fixes https://github.com/bazelbuild/bazel/issues/5157 If a user's default system locale is not `en`, `en_US` or `en_UK`, there may be a chance that `String#toUpperCase` will result in a string that does not exist in the Enum declaration. This is the case in #5157. To fix this, it's either 1) setting the Locale in the individual `toUpperCase` calls or 2) set Locale to English by default from `Bazel.java`. I chose the first because it seemed less intrusive, but I'm open to suggestions. Closes #5184. PiperOrigin-RevId: 196261078
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/packages')
-rw-r--r--src/main/java/com/google/devtools/build/lib/packages/FilesetEntry.java3
-rw-r--r--src/main/java/com/google/devtools/build/lib/packages/License.java5
-rw-r--r--src/main/java/com/google/devtools/build/lib/packages/TestTimeout.java5
3 files changed, 8 insertions, 5 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/packages/FilesetEntry.java b/src/main/java/com/google/devtools/build/lib/packages/FilesetEntry.java
index b6a35eedcf..8b41b8075f 100644
--- a/src/main/java/com/google/devtools/build/lib/packages/FilesetEntry.java
+++ b/src/main/java/com/google/devtools/build/lib/packages/FilesetEntry.java
@@ -30,6 +30,7 @@ import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.List;
+import java.util.Locale;
import java.util.Set;
import javax.annotation.Nullable;
@@ -98,7 +99,7 @@ public final class FilesetEntry implements SkylarkValue {
DEREFERENCE;
public static SymlinkBehavior parse(String value) throws IllegalArgumentException {
- return valueOf(value.toUpperCase());
+ return valueOf(value.toUpperCase(Locale.ENGLISH));
}
@Override
diff --git a/src/main/java/com/google/devtools/build/lib/packages/License.java b/src/main/java/com/google/devtools/build/lib/packages/License.java
index 3a35baa3c9..4a8c758a65 100644
--- a/src/main/java/com/google/devtools/build/lib/packages/License.java
+++ b/src/main/java/com/google/devtools/build/lib/packages/License.java
@@ -33,6 +33,7 @@ import java.util.Collection;
import java.util.Collections;
import java.util.EnumSet;
import java.util.List;
+import java.util.Locale;
import java.util.Set;
/** Support for license and distribution checking. */
@@ -124,7 +125,7 @@ public final class License {
Set<DistributionType> result = EnumSet.noneOf(DistributionType.class);
for (String distStr : distStrings) {
try {
- DistributionType dist = DistributionType.valueOf(distStr.toUpperCase());
+ DistributionType dist = DistributionType.valueOf(distStr.toUpperCase(Locale.ENGLISH));
result.add(dist);
} catch (IllegalArgumentException e) {
throw new LicenseParsingException("Invalid distribution type '" + distStr + "'");
@@ -216,7 +217,7 @@ public final class License {
}
} else {
try {
- licenseTypes.add(LicenseType.valueOf(str.toUpperCase()));
+ licenseTypes.add(LicenseType.valueOf(str.toUpperCase(Locale.ENGLISH)));
} catch (IllegalArgumentException e) {
throw new LicenseParsingException("invalid license type: '" + str + "'");
}
diff --git a/src/main/java/com/google/devtools/build/lib/packages/TestTimeout.java b/src/main/java/com/google/devtools/build/lib/packages/TestTimeout.java
index 6e834a70d7..86ff65b9e2 100644
--- a/src/main/java/com/google/devtools/build/lib/packages/TestTimeout.java
+++ b/src/main/java/com/google/devtools/build/lib/packages/TestTimeout.java
@@ -29,6 +29,7 @@ import java.util.Arrays;
import java.util.EnumMap;
import java.util.Iterator;
import java.util.List;
+import java.util.Locale;
import java.util.Map;
import java.util.Set;
@@ -123,7 +124,7 @@ public enum TestTimeout {
return null;
}
try {
- return TestTimeout.valueOf(attr.toUpperCase());
+ return TestTimeout.valueOf(attr.toUpperCase(Locale.ENGLISH));
} catch (IllegalArgumentException e) {
return null;
}
@@ -181,7 +182,7 @@ public enum TestTimeout {
return null; // attribute values must be lowercase
}
try {
- return TestTimeout.valueOf(attr.toUpperCase());
+ return TestTimeout.valueOf(attr.toUpperCase(Locale.ENGLISH));
} catch (IllegalArgumentException e) {
return null;
}