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
diff --git a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/sharding/ShardingFilters.java b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/sharding/ShardingFilters.java
index 2a5b79c..a92de41 100644
--- a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/sharding/ShardingFilters.java
+++ b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/sharding/ShardingFilters.java
@@ -15,14 +15,12 @@
 package com.google.testing.junit.runner.sharding;
 
 import com.google.testing.junit.runner.sharding.api.ShardingFilterFactory;
-
+import java.util.Collection;
+import java.util.Locale;
+import javax.inject.Inject;
 import org.junit.runner.Description;
 import org.junit.runner.manipulation.Filter;
 
-import java.util.Collection;
-
-import javax.inject.Inject;
-
 /**
  * A factory for test sharding filters.
  */
@@ -97,7 +95,7 @@
     }
     ShardingFilterFactory shardingFilterFactory;
     try {
-      shardingFilterFactory = ShardingStrategy.valueOf(strategy.toUpperCase());
+      shardingFilterFactory = ShardingStrategy.valueOf(strategy.toUpperCase(Locale.ENGLISH));
     } catch (IllegalArgumentException e) {
       try {
         ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
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 b6a35ee..8b41b80 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.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 @@
     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 3a35baa..4a8c758 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.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 @@
       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 @@
         }
       } 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 6e834a7..86ff65b 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.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 @@
       return null;
     }
     try {
-      return TestTimeout.valueOf(attr.toUpperCase());
+      return TestTimeout.valueOf(attr.toUpperCase(Locale.ENGLISH));
     } catch (IllegalArgumentException e) {
       return null;
     }
@@ -181,7 +182,7 @@
       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;
     }
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppToolchainInfo.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppToolchainInfo.java
index 1656d11..bd67bbb 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppToolchainInfo.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppToolchainInfo.java
@@ -45,6 +45,7 @@
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
+import java.util.Locale;
 import java.util.Map;
 import java.util.Set;
 import javax.annotation.Nullable;
@@ -335,7 +336,8 @@
     Set<ArtifactCategory> definedCategories = new HashSet<>();
     for (ArtifactNamePattern pattern : toolchainBuilder.getArtifactNamePatternList()) {
       try {
-        definedCategories.add(ArtifactCategory.valueOf(pattern.getCategoryName().toUpperCase()));
+        definedCategories.add(
+            ArtifactCategory.valueOf(pattern.getCategoryName().toUpperCase(Locale.ENGLISH)));
       } catch (IllegalArgumentException e) {
         // Invalid category name, will be detected later.
         continue;
diff --git a/src/tools/android/java/com/google/devtools/build/android/xml/SimpleXmlResourceValue.java b/src/tools/android/java/com/google/devtools/build/android/xml/SimpleXmlResourceValue.java
index dd28f10..e2d5caf 100644
--- a/src/tools/android/java/com/google/devtools/build/android/xml/SimpleXmlResourceValue.java
+++ b/src/tools/android/java/com/google/devtools/build/android/xml/SimpleXmlResourceValue.java
@@ -33,6 +33,7 @@
 import java.io.IOException;
 import java.io.OutputStream;
 import java.util.Arrays;
+import java.util.Locale;
 import java.util.Objects;
 import javax.annotation.Nullable;
 import javax.annotation.concurrent.Immutable;
@@ -283,7 +284,7 @@
     }
 
     return of(
-        Type.valueOf(resourceType.toString().toUpperCase()),
+        Type.valueOf(resourceType.toString().toUpperCase(Locale.ENGLISH)),
         ImmutableMap.of(),
         stringValue);
   }