Skip to content

Commit

Permalink
HADOOP-11602. Fix toUpperCase/toLowerCase to use Locale.ENGLISH. (ozawa)
Browse files Browse the repository at this point in the history
  • Loading branch information
oza committed Feb 19, 2015
1 parent 18fb421 commit 946456c
Show file tree
Hide file tree
Showing 98 changed files with 331 additions and 191 deletions.
Expand Up @@ -21,14 +21,15 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

class StabilityOptions {
public static final String STABLE_OPTION = "-stable";
public static final String EVOLVING_OPTION = "-evolving";
public static final String UNSTABLE_OPTION = "-unstable";

public static Integer optionLength(String option) {
String opt = option.toLowerCase();
String opt = option.toLowerCase(Locale.ENGLISH);
if (opt.equals(UNSTABLE_OPTION)) return 1;
if (opt.equals(EVOLVING_OPTION)) return 1;
if (opt.equals(STABLE_OPTION)) return 1;
Expand All @@ -38,7 +39,7 @@ public static Integer optionLength(String option) {
public static void validOptions(String[][] options,
DocErrorReporter reporter) {
for (int i = 0; i < options.length; i++) {
String opt = options[i][0].toLowerCase();
String opt = options[i][0].toLowerCase(Locale.ENGLISH);
if (opt.equals(UNSTABLE_OPTION)) {
RootDocProcessor.stability = UNSTABLE_OPTION;
} else if (opt.equals(EVOLVING_OPTION)) {
Expand Down
Expand Up @@ -14,6 +14,7 @@
package org.apache.hadoop.security.authentication.server;

import java.io.IOException;
import java.util.Locale;
import java.util.Properties;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
Expand Down Expand Up @@ -68,7 +69,8 @@ public void init(Properties config) throws ServletException {
NON_BROWSER_USER_AGENTS, NON_BROWSER_USER_AGENTS_DEFAULT)
.split("\\W*,\\W*");
for (int i = 0; i < nonBrowserUserAgents.length; i++) {
nonBrowserUserAgents[i] = nonBrowserUserAgents[i].toLowerCase();
nonBrowserUserAgents[i] =
nonBrowserUserAgents[i].toLowerCase(Locale.ENGLISH);
}
}

Expand Down Expand Up @@ -120,7 +122,7 @@ protected boolean isBrowser(String userAgent) {
if (userAgent == null) {
return false;
}
userAgent = userAgent.toLowerCase();
userAgent = userAgent.toLowerCase(Locale.ENGLISH);
boolean isBrowser = true;
for (String nonBrowserUserAgent : nonBrowserUserAgents) {
if (userAgent.contains(nonBrowserUserAgent)) {
Expand Down
Expand Up @@ -21,6 +21,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import java.util.regex.Pattern;

import org.apache.directory.server.kerberos.shared.keytab.Keytab;
Expand Down Expand Up @@ -58,24 +59,25 @@ public void testGetServerPrincipal() throws IOException {

// send null hostname
Assert.assertEquals("When no hostname is sent",
service + "/" + localHostname.toLowerCase(),
service + "/" + localHostname.toLowerCase(Locale.ENGLISH),
KerberosUtil.getServicePrincipal(service, null));
// send empty hostname
Assert.assertEquals("When empty hostname is sent",
service + "/" + localHostname.toLowerCase(),
service + "/" + localHostname.toLowerCase(Locale.ENGLISH),
KerberosUtil.getServicePrincipal(service, ""));
// send 0.0.0.0 hostname
Assert.assertEquals("When 0.0.0.0 hostname is sent",
service + "/" + localHostname.toLowerCase(),
service + "/" + localHostname.toLowerCase(Locale.ENGLISH),
KerberosUtil.getServicePrincipal(service, "0.0.0.0"));
// send uppercase hostname
Assert.assertEquals("When uppercase hostname is sent",
service + "/" + testHost.toLowerCase(),
service + "/" + testHost.toLowerCase(Locale.ENGLISH),
KerberosUtil.getServicePrincipal(service, testHost));
// send lowercase hostname
Assert.assertEquals("When lowercase hostname is sent",
service + "/" + testHost.toLowerCase(),
KerberosUtil.getServicePrincipal(service, testHost.toLowerCase()));
service + "/" + testHost.toLowerCase(Locale.ENGLISH),
KerberosUtil.getServicePrincipal(
service, testHost.toLowerCase(Locale.ENGLISH)));
}

@Test
Expand Down
2 changes: 2 additions & 0 deletions hadoop-common-project/hadoop-common/CHANGES.txt
Expand Up @@ -405,6 +405,8 @@ Trunk (Unreleased)

HADOOP-11585. Fix formatting in Tracing.md (Masatake Iwasaki via aw)

HADOOP-11602. Fix toUpperCase/toLowerCase to use Locale.ENGLISH. (ozawa)

OPTIMIZATIONS

HADOOP-7761. Improve the performance of raw comparisons. (todd)
Expand Down
Expand Up @@ -46,6 +46,7 @@
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;
Expand Down Expand Up @@ -1451,7 +1452,7 @@ public boolean getBoolean(String name, boolean defaultValue) {
return defaultValue;
}

valueString = valueString.toLowerCase();
valueString = valueString.toLowerCase(Locale.ENGLISH);

if ("true".equals(valueString))
return true;
Expand Down
Expand Up @@ -18,6 +18,7 @@

package org.apache.hadoop.crypto;

import java.util.Locale;
import org.apache.hadoop.classification.InterfaceAudience;

/**
Expand Down Expand Up @@ -97,7 +98,7 @@ public String getConfigSuffix() {
String[] parts = name.split("/");
StringBuilder suffix = new StringBuilder();
for (String part : parts) {
suffix.append(".").append(part.toLowerCase());
suffix.append(".").append(part.toLowerCase(Locale.ENGLISH));
}

return suffix.toString();
Expand Down
Expand Up @@ -53,6 +53,7 @@
import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReadWriteLock;
Expand Down Expand Up @@ -422,7 +423,7 @@ public Metadata getMetadata(String name) throws IOException {
@Override
public KeyVersion createKey(String name, byte[] material,
Options options) throws IOException {
Preconditions.checkArgument(name.equals(name.toLowerCase()),
Preconditions.checkArgument(name.equals(name.toLowerCase(Locale.ENGLISH)),
"Uppercase key names are unsupported: %s", name);
writeLock.lock();
try {
Expand Down
Expand Up @@ -33,6 +33,7 @@
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.ServiceLoader;
Expand Down Expand Up @@ -2795,8 +2796,10 @@ static class Key {
}

Key(URI uri, Configuration conf, long unique) throws IOException {
scheme = uri.getScheme()==null?"":uri.getScheme().toLowerCase();
authority = uri.getAuthority()==null?"":uri.getAuthority().toLowerCase();
scheme = uri.getScheme() == null ?
"" : uri.getScheme().toLowerCase(Locale.ENGLISH);
authority = uri.getAuthority() == null ?
"" : uri.getAuthority().toLowerCase(Locale.ENGLISH);
this.unique = unique;

this.ugi = UserGroupInformation.getCurrentUser();
Expand Down
Expand Up @@ -20,6 +20,7 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Locale;

import com.google.common.base.Objects;

Expand Down Expand Up @@ -106,7 +107,7 @@ public String toString() {
sb.append("default:");
}
if (type != null) {
sb.append(type.toString().toLowerCase());
sb.append(type.toString().toLowerCase(Locale.ENGLISH));
}
sb.append(':');
if (name != null) {
Expand Down Expand Up @@ -263,7 +264,8 @@ public static AclEntry parseAclEntry(String aclStr,

AclEntryType aclType = null;
try {
aclType = Enum.valueOf(AclEntryType.class, split[index].toUpperCase());
aclType = Enum.valueOf(
AclEntryType.class, split[index].toUpperCase(Locale.ENGLISH));
builder.setType(aclType);
index++;
} catch (IllegalArgumentException iae) {
Expand Down
Expand Up @@ -19,6 +19,7 @@

import java.io.IOException;
import java.util.Deque;
import java.util.Locale;

import org.apache.hadoop.fs.GlobPattern;
import org.apache.hadoop.fs.shell.PathData;
Expand Down Expand Up @@ -73,7 +74,7 @@ public void addArguments(Deque<String> args) {
public void prepare() throws IOException {
String argPattern = getArgument(1);
if (!caseSensitive) {
argPattern = argPattern.toLowerCase();
argPattern = argPattern.toLowerCase(Locale.ENGLISH);
}
globPattern = new GlobPattern(argPattern);
}
Expand All @@ -82,7 +83,7 @@ public void prepare() throws IOException {
public Result apply(PathData item, int depth) throws IOException {
String name = getPath(item).getName();
if (!caseSensitive) {
name = name.toLowerCase();
name = name.toLowerCase(Locale.ENGLISH);
}
if (globPattern.matches(name)) {
return Result.PASS;
Expand Down
Expand Up @@ -65,10 +65,10 @@ private void addCodec(CompressionCodec codec) {
codecsByClassName.put(codec.getClass().getCanonicalName(), codec);

String codecName = codec.getClass().getSimpleName();
codecsByName.put(codecName.toLowerCase(), codec);
codecsByName.put(codecName.toLowerCase(Locale.ENGLISH), codec);
if (codecName.endsWith("Codec")) {
codecName = codecName.substring(0, codecName.length() - "Codec".length());
codecsByName.put(codecName.toLowerCase(), codec);
codecsByName.put(codecName.toLowerCase(Locale.ENGLISH), codec);
}
}

Expand Down Expand Up @@ -240,7 +240,7 @@ public CompressionCodec getCodecByName(String codecName) {
CompressionCodec codec = getCodecByClassName(codecName);
if (codec == null) {
// trying to get the codec by name in case the name was specified instead a class
codec = codecsByName.get(codecName.toLowerCase());
codec = codecsByName.get(codecName.toLowerCase(Locale.ENGLISH));
}
return codec;
}
Expand Down
Expand Up @@ -85,12 +85,13 @@ class MetricsConfig extends SubsetConfiguration {
private ClassLoader pluginLoader;

MetricsConfig(Configuration c, String prefix) {
super(c, prefix.toLowerCase(Locale.US), ".");
super(c, prefix.toLowerCase(Locale.ENGLISH), ".");
}

static MetricsConfig create(String prefix) {
return loadFirst(prefix, "hadoop-metrics2-"+ prefix.toLowerCase(Locale.US)
+".properties", DEFAULT_FILE_NAME);
return loadFirst(prefix, "hadoop-metrics2" + "-"
+ prefix.toLowerCase(Locale.ENGLISH)
+".properties", DEFAULT_FILE_NAME);
}

static MetricsConfig create(String prefix, String... fileNames) {
Expand Down
Expand Up @@ -617,6 +617,6 @@ private InitMode initMode() {
String m = System.getProperty(MS_INIT_MODE_KEY);
String m2 = m == null ? System.getenv(MS_INIT_MODE_KEY) : m;
return InitMode.valueOf((m2 == null ? InitMode.NORMAL.name() : m2)
.toUpperCase(Locale.US));
.toUpperCase(Locale.ENGLISH));
}
}
Expand Up @@ -182,7 +182,8 @@ private static String replacePattern(String[] components, String hostname)
if (fqdn == null || fqdn.isEmpty() || fqdn.equals("0.0.0.0")) {
fqdn = getLocalHostName();
}
return components[0] + "/" + fqdn.toLowerCase(Locale.US) + "@" + components[2];
return components[0] + "/" + fqdn.toLowerCase(Locale.ENGLISH) + "@"
+ components[2];
}

static String getLocalHostName() throws UnknownHostException {
Expand Down Expand Up @@ -379,7 +380,7 @@ public static Text buildTokenService(InetSocketAddress addr) {
}
host = addr.getAddress().getHostAddress();
} else {
host = addr.getHostName().toLowerCase();
host = addr.getHostName().toLowerCase(Locale.ENGLISH);
}
return new Text(host + ":" + addr.getPort());
}
Expand Down
Expand Up @@ -19,6 +19,7 @@

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Locale;
import java.util.Map;
import java.util.TreeMap;

Expand Down Expand Up @@ -138,7 +139,8 @@ static Map<String, String> getSaslProperties(Configuration conf) {
QualityOfProtection.PRIVACY.toString());

for (int i=0; i < qop.length; i++) {
qop[i] = QualityOfProtection.valueOf(qop[i].toUpperCase()).getSaslQop();
qop[i] = QualityOfProtection.valueOf(
qop[i].toUpperCase(Locale.ENGLISH)).getSaslQop();
}

saslProps.put(Sasl.QOP, StringUtils.join(",", qop));
Expand Down
Expand Up @@ -33,6 +33,7 @@
import java.security.GeneralSecurityException;
import java.security.KeyStore;
import java.text.MessageFormat;
import java.util.Locale;

/**
* {@link KeyStoresFactory} implementation that reads the certificates from
Expand Down Expand Up @@ -94,7 +95,8 @@ public class FileBasedKeyStoresFactory implements KeyStoresFactory {
@VisibleForTesting
public static String resolvePropertyName(SSLFactory.Mode mode,
String template) {
return MessageFormat.format(template, mode.toString().toLowerCase());
return MessageFormat.format(
template, mode.toString().toLowerCase(Locale.ENGLISH));
}

/**
Expand Down
Expand Up @@ -33,6 +33,7 @@
import java.io.IOException;
import java.net.HttpURLConnection;
import java.security.GeneralSecurityException;
import java.util.Locale;

/**
* Factory that creates SSLEngine and SSLSocketFactory instances using
Expand Down Expand Up @@ -138,7 +139,7 @@ public void init() throws GeneralSecurityException, IOException {
private HostnameVerifier getHostnameVerifier(Configuration conf)
throws GeneralSecurityException, IOException {
return getHostnameVerifier(conf.get(SSL_HOSTNAME_VERIFIER_KEY, "DEFAULT").
trim().toUpperCase());
trim().toUpperCase(Locale.ENGLISH));
}

public static HostnameVerifier getHostnameVerifier(String verifier)
Expand Down
Expand Up @@ -41,6 +41,7 @@
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.TreeSet;
Expand Down Expand Up @@ -365,7 +366,7 @@ public void check(final String[] hosts, final String[] cns,
buf.append('<');
for (int i = 0; i < hosts.length; i++) {
String h = hosts[i];
h = h != null ? h.trim().toLowerCase() : "";
h = h != null ? h.trim().toLowerCase(Locale.ENGLISH) : "";
hosts[i] = h;
if (i > 0) {
buf.append('/');
Expand Down Expand Up @@ -406,7 +407,7 @@ public void check(final String[] hosts, final String[] cns,
out:
for (Iterator<String> it = names.iterator(); it.hasNext();) {
// Don't trim the CN, though!
final String cn = it.next().toLowerCase();
final String cn = it.next().toLowerCase(Locale.ENGLISH);
// Store CN in StringBuffer in case we need to report an error.
buf.append(" <");
buf.append(cn);
Expand All @@ -424,7 +425,8 @@ public void check(final String[] hosts, final String[] cns,
acceptableCountryWildcard(cn);

for (int i = 0; i < hosts.length; i++) {
final String hostName = hosts[i].trim().toLowerCase();
final String hostName =
hosts[i].trim().toLowerCase(Locale.ENGLISH);
if (doWildcard) {
match = hostName.endsWith(cn.substring(1));
if (match && strictWithSubDomains) {
Expand Down Expand Up @@ -479,7 +481,7 @@ public static boolean acceptableCountryWildcard(final String cn) {
}

public static boolean isLocalhost(String host) {
host = host != null ? host.trim().toLowerCase() : "";
host = host != null ? host.trim().toLowerCase(Locale.ENGLISH) : "";
if (host.startsWith("::1")) {
int x = host.lastIndexOf('%');
if (x >= 0) {
Expand Down

0 comments on commit 946456c

Please sign in to comment.