OpenJDK / amber / amber
changeset 10369:e9d2e59e53f0
7059542: JNDI name operations should be locale independent
Reviewed-by: weijun
line wrap: on
line diff
--- a/jdk/src/share/classes/com/sun/jndi/ldap/ClientId.java Sat Aug 27 15:40:45 2011 +0100 +++ b/jdk/src/share/classes/com/sun/jndi/ldap/ClientId.java Mon Aug 29 05:55:26 2011 -0700 @@ -25,6 +25,7 @@ package com.sun.jndi.ldap; +import java.util.Locale; import java.util.Arrays; // JDK 1.2 import java.io.OutputStream; import javax.naming.ldap.Control; @@ -71,7 +72,7 @@ ClientId(int version, String hostname, int port, String protocol, Control[] bindCtls, OutputStream trace, String socketFactory) { this.version = version; - this.hostname = hostname.toLowerCase(); // ignore case + this.hostname = hostname.toLowerCase(Locale.ENGLISH); // ignore case this.port = port; this.protocol = protocol; this.bindCtls = (bindCtls != null ? bindCtls.clone() : null); @@ -83,13 +84,15 @@ if ((socketFactory != null) && !socketFactory.equals(LdapCtx.DEFAULT_SSL_FACTORY)) { try { - Class<?> socketFactoryClass = Obj.helper.loadClass(socketFactory); + Class<?> socketFactoryClass = + Obj.helper.loadClass(socketFactory); Class<?> objClass = Class.forName("java.lang.Object"); this.sockComparator = socketFactoryClass.getMethod( "compare", new Class<?>[]{objClass, objClass}); - Method getDefault = - socketFactoryClass.getMethod("getDefault", new Class<?>[]{}); - this.factory = (SocketFactory) getDefault.invoke(null, new Object[]{}); + Method getDefault = socketFactoryClass.getMethod( + "getDefault", new Class<?>[]{}); + this.factory = + (SocketFactory)getDefault.invoke(null, new Object[]{}); } catch (Exception e) { // Ignore it here, the same exceptions are/will be handled by // LdapPoolManager and Connection classes.
--- a/jdk/src/share/classes/com/sun/jndi/ldap/LdapClient.java Sat Aug 27 15:40:45 2011 +0100 +++ b/jdk/src/share/classes/com/sun/jndi/ldap/LdapClient.java Mon Aug 29 05:55:26 2011 -0700 @@ -26,6 +26,7 @@ package com.sun.jndi.ldap; import java.io.*; +import java.util.Locale; import java.util.Vector; import java.util.Hashtable; @@ -738,14 +739,15 @@ if (hasBinaryValues) { la.add(ber.parseOctetString(ber.peekByte(), len)); } else { - la.add(ber.parseStringWithTag(Ber.ASN_SIMPLE_STRING, isLdapv3, len)); + la.add(ber.parseStringWithTag( + Ber.ASN_SIMPLE_STRING, isLdapv3, len)); } return len[0]; } private boolean isBinaryValued(String attrid, Hashtable<String, Boolean> binaryAttrs) { - String id = attrid.toLowerCase(); + String id = attrid.toLowerCase(Locale.ENGLISH); return ((id.indexOf(";binary") != -1) || defaultBinaryAttrs.containsKey(id) || @@ -753,8 +755,8 @@ } // package entry point; used by Connection - static void parseResult(BerDecoder replyBer, LdapResult res, boolean isLdapv3) - throws IOException { + static void parseResult(BerDecoder replyBer, LdapResult res, + boolean isLdapv3) throws IOException { res.status = replyBer.parseEnumeration(); res.matchedDN = replyBer.parseString(isLdapv3);
--- a/jdk/src/share/classes/com/sun/jndi/ldap/LdapCtx.java Sat Aug 27 15:40:45 2011 +0100 +++ b/jdk/src/share/classes/com/sun/jndi/ldap/LdapCtx.java Mon Aug 29 05:55:26 2011 -0700 @@ -33,6 +33,7 @@ import javax.naming.ldap.LdapName; import javax.naming.ldap.Rdn; +import java.util.Locale; import java.util.Vector; import java.util.Hashtable; import java.util.List; @@ -2597,7 +2598,7 @@ } else { binaryAttrs = new Hashtable<>(11, 0.75f); StringTokenizer tokens = - new StringTokenizer(attrIds.toLowerCase(), " "); + new StringTokenizer(attrIds.toLowerCase(Locale.ENGLISH), " "); while (tokens.hasMoreTokens()) { binaryAttrs.put(tokens.nextToken(), Boolean.TRUE);
--- a/jdk/src/share/classes/com/sun/jndi/ldap/LdapName.java Sat Aug 27 15:40:45 2011 +0100 +++ b/jdk/src/share/classes/com/sun/jndi/ldap/LdapName.java Mon Aug 29 05:55:26 2011 -0700 @@ -28,6 +28,7 @@ import java.util.Enumeration; import java.util.Vector; +import java.util.Locale; import javax.naming.*; import javax.naming.directory.Attributes; @@ -707,7 +708,7 @@ TypeAndValue that = (TypeAndValue)obj; - int diff = type.toUpperCase().compareTo(that.type.toUpperCase()); + int diff = type.compareToIgnoreCase(that.type); if (diff != 0) { return diff; } @@ -730,7 +731,7 @@ public int hashCode() { // If two objects are equal, their hash codes must match. - return (type.toUpperCase().hashCode() + + return (type.toUpperCase(Locale.ENGLISH).hashCode() + getValueComparable().hashCode()); } @@ -764,11 +765,12 @@ // cache result if (binary) { - comparable = value.toUpperCase(); + comparable = value.toUpperCase(Locale.ENGLISH); } else { comparable = (String)unescapeValue(value); if (!valueCaseSensitive) { - comparable = comparable.toUpperCase(); // ignore case + // ignore case + comparable = comparable.toUpperCase(Locale.ENGLISH); } } return comparable; @@ -836,7 +838,7 @@ buf.append(Character.forDigit(0xF & b, 16)); } - return (new String(buf)).toUpperCase(); + return (new String(buf)).toUpperCase(Locale.ENGLISH); } /*
--- a/jdk/src/share/classes/com/sun/jndi/ldap/LdapPoolManager.java Sat Aug 27 15:40:45 2011 +0100 +++ b/jdk/src/share/classes/com/sun/jndi/ldap/LdapPoolManager.java Mon Aug 29 05:55:26 2011 -0700 @@ -28,6 +28,7 @@ import java.io.PrintStream; import java.io.OutputStream; import java.util.Hashtable; +import java.util.Locale; import java.util.StringTokenizer; import javax.naming.ldap.Control; @@ -133,7 +134,7 @@ String mech; int p; for (int i = 0; i < count; i++) { - mech = parser.nextToken().toLowerCase(); + mech = parser.nextToken().toLowerCase(Locale.ENGLISH); if (mech.equals("anonymous")) { mech = "none"; }
--- a/jdk/src/share/classes/com/sun/jndi/toolkit/dir/HierMemDirCtx.java Sat Aug 27 15:40:45 2011 +0100 +++ b/jdk/src/share/classes/com/sun/jndi/toolkit/dir/HierMemDirCtx.java Mon Aug 29 05:55:26 2011 -0700 @@ -910,7 +910,7 @@ public int hashCode() { if (hashValue == -1) { - String name = toString().toUpperCase(); + String name = toString().toUpperCase(Locale.ENGLISH); int len = name.length(); int off = 0; char val[] = new char[len];
--- a/jdk/src/share/classes/com/sun/jndi/toolkit/dir/SearchFilter.java Sat Aug 27 15:40:45 2011 +0100 +++ b/jdk/src/share/classes/com/sun/jndi/toolkit/dir/SearchFilter.java Mon Aug 29 05:55:26 2011 -0700 @@ -29,6 +29,7 @@ import java.util.Enumeration; import java.util.StringTokenizer; import java.util.Vector; +import java.util.Locale; /** * A class for parsing LDAP search filters (defined in RFC 1960, 2254) @@ -395,19 +396,21 @@ // do we need to begin with the first token? if(proto.charAt(0) != WILDCARD_TOKEN && - !value.toString().toLowerCase().startsWith( - subStrs.nextToken().toLowerCase())) { - if(debug) {System.out.println("faild initial test");} + !value.toString().toLowerCase(Locale.ENGLISH).startsWith( + subStrs.nextToken().toLowerCase(Locale.ENGLISH))) { + if(debug) { + System.out.println("faild initial test"); + } return false; } - while(subStrs.hasMoreTokens()) { String currentStr = subStrs.nextToken(); if (debug) {System.out.println("looking for \"" + currentStr +"\"");} - currentPos = value.toLowerCase().indexOf( - currentStr.toLowerCase(), currentPos); + currentPos = value.toLowerCase(Locale.ENGLISH).indexOf( + currentStr.toLowerCase(Locale.ENGLISH), currentPos); + if(currentPos == -1) { return false; }
--- a/jdk/src/share/classes/com/sun/security/ntlm/NTLM.java Sat Aug 27 15:40:45 2011 +0100 +++ b/jdk/src/share/classes/com/sun/security/ntlm/NTLM.java Mon Aug 29 05:55:26 2011 -0700 @@ -33,6 +33,7 @@ import java.security.NoSuchAlgorithmException; import java.security.spec.InvalidKeySpecException; import java.util.Arrays; +import java.util.Locale; import javax.crypto.BadPaddingException; import javax.crypto.Cipher; import javax.crypto.IllegalBlockSizeException; @@ -410,7 +411,8 @@ static byte[] getP1(char[] password) { try { - return new String(password).toUpperCase().getBytes("ISO8859_1"); + return new String(password).toUpperCase( + Locale.ENGLISH).getBytes("ISO8859_1"); } catch (UnsupportedEncodingException ex) { return null; }
--- a/jdk/src/share/classes/java/security/KeyRep.java Sat Aug 27 15:40:45 2011 +0100 +++ b/jdk/src/share/classes/java/security/KeyRep.java Mon Aug 29 05:55:26 2011 -0700 @@ -26,6 +26,7 @@ package java.security; import java.io.*; +import java.util.Locale; import java.security.spec.PKCS8EncodedKeySpec; import java.security.spec.X509EncodedKeySpec; @@ -137,7 +138,7 @@ this.type = type; this.algorithm = algorithm; - this.format = format.toUpperCase(); + this.format = format.toUpperCase(Locale.ENGLISH); this.encoded = encoded.clone(); }
--- a/jdk/src/share/classes/java/security/Security.java Sat Aug 27 15:40:45 2011 +0100 +++ b/jdk/src/share/classes/java/security/Security.java Mon Aug 29 05:55:26 2011 -0700 @@ -1087,8 +1087,10 @@ // Check the keys for each provider. for (Enumeration<Object> e = providers[i].keys(); e.hasMoreElements(); ) { - String currentKey = ((String)e.nextElement()).toUpperCase(); - if (currentKey.startsWith(serviceName.toUpperCase())) { + String currentKey = + ((String)e.nextElement()).toUpperCase(Locale.ENGLISH); + if (currentKey.startsWith( + serviceName.toUpperCase(Locale.ENGLISH))) { // We should skip the currentKey if it contains a // whitespace. The reason is: such an entry in the // provider property contains attributes for the @@ -1096,7 +1098,8 @@ // in entries which lead to the implementation // classes. if (currentKey.indexOf(" ") < 0) { - result.add(currentKey.substring(serviceName.length() + 1)); + result.add(currentKey.substring( + serviceName.length() + 1)); } } }
--- a/jdk/src/share/classes/javax/naming/NameImpl.java Sat Aug 27 15:40:45 2011 +0100 +++ b/jdk/src/share/classes/javax/naming/NameImpl.java Mon Aug 29 05:55:26 2011 -0700 @@ -25,6 +25,7 @@ package javax.naming; +import java.util.Locale; import java.util.Vector; import java.util.Enumeration; import java.util.Properties; @@ -216,7 +217,8 @@ } private static boolean toBoolean(String name) { - return ((name != null) && name.toLowerCase().equals("true")); + return ((name != null) && + name.toLowerCase(Locale.ENGLISH).equals("true")); } private final void recordNamingConvention(Properties p) { @@ -526,11 +528,14 @@ comp1 = comp1.trim(); comp2 = comp2.trim(); } + + int local; if (syntaxCaseInsensitive) { - comp1 = comp1.toLowerCase(); - comp2 = comp2.toLowerCase(); + local = comp1.compareToIgnoreCase(comp2); + } else { + local = comp1.compareTo(comp2); } - int local = comp1.compareTo(comp2); + if (local != 0) { return local; } @@ -696,7 +701,7 @@ comp = comp.trim(); } if (syntaxCaseInsensitive) { - comp = comp.toLowerCase(); + comp = comp.toLowerCase(Locale.ENGLISH); } hash += comp.hashCode();
--- a/jdk/src/share/classes/javax/naming/directory/BasicAttributes.java Sat Aug 27 15:40:45 2011 +0100 +++ b/jdk/src/share/classes/javax/naming/directory/BasicAttributes.java Mon Aug 29 05:55:26 2011 -0700 @@ -28,6 +28,7 @@ import java.util.Hashtable; import java.util.Enumeration; +import java.util.Locale; import javax.naming.NamingException; import javax.naming.NamingEnumeration; @@ -160,7 +161,7 @@ public Attribute get(String attrID) { Attribute attr = attrs.get( - ignoreCase ? attrID.toLowerCase() : attrID); + ignoreCase ? attrID.toLowerCase(Locale.ENGLISH) : attrID); return (attr); } @@ -179,13 +180,13 @@ public Attribute put(Attribute attr) { String id = attr.getID(); if (ignoreCase) { - id = id.toLowerCase(); + id = id.toLowerCase(Locale.ENGLISH); } return attrs.put(id, attr); } public Attribute remove(String attrID) { - String id = (ignoreCase ? attrID.toLowerCase() : attrID); + String id = (ignoreCase ? attrID.toLowerCase(Locale.ENGLISH) : attrID); return attrs.remove(id); }
--- a/jdk/src/share/classes/javax/naming/ldap/Rdn.java Sat Aug 27 15:40:45 2011 +0100 +++ b/jdk/src/share/classes/javax/naming/ldap/Rdn.java Mon Aug 29 05:55:26 2011 -0700 @@ -28,6 +28,7 @@ import java.util.Iterator; import java.util.NoSuchElementException; import java.util.ArrayList; +import java.util.Locale; import java.util.Collections; import javax.naming.InvalidNameException; @@ -434,8 +435,7 @@ } public int compareTo(RdnEntry that) { - int diff = type.toUpperCase().compareTo( - that.type.toUpperCase()); + int diff = type.compareToIgnoreCase(that.type); if (diff != 0) { return diff; } @@ -462,7 +462,7 @@ } public int hashCode() { - return (type.toUpperCase().hashCode() + + return (type.toUpperCase(Locale.ENGLISH).hashCode() + getValueComparable().hashCode()); } @@ -479,7 +479,7 @@ if (value instanceof byte[]) { comparable = escapeBinaryValue((byte[]) value); } else { - comparable = ((String) value).toUpperCase(); + comparable = ((String) value).toUpperCase(Locale.ENGLISH); } return comparable; } @@ -569,7 +569,6 @@ builder.append(Character.forDigit(0xF & b, 16)); } return builder.toString(); - // return builder.toString().toUpperCase(); } /**
--- a/jdk/src/share/classes/sun/security/jgss/krb5/Krb5NameElement.java Sat Aug 27 15:40:45 2011 +0100 +++ b/jdk/src/share/classes/sun/security/jgss/krb5/Krb5NameElement.java Mon Aug 29 05:55:26 2011 -0700 @@ -35,6 +35,7 @@ import java.net.InetAddress; import java.net.UnknownHostException; import java.security.Provider; +import java.util.Locale; /** * Implements the GSSNameSpi for the krb5 mechanism. @@ -184,7 +185,7 @@ } catch (UnknownHostException e) { // use hostname as it is } - hostName = hostName.toLowerCase(); + hostName = hostName.toLowerCase(Locale.ENGLISH); temp = temp.append('/').append(hostName); return temp.toString();
--- a/jdk/src/share/classes/sun/security/krb5/PrincipalName.java Sat Aug 27 15:40:45 2011 +0100 +++ b/jdk/src/share/classes/sun/security/krb5/PrincipalName.java Mon Aug 29 05:55:26 2011 -0700 @@ -35,6 +35,7 @@ import sun.security.util.*; import java.net.*; import java.util.Vector; +import java.util.Locale; import java.io.IOException; import java.math.BigInteger; import sun.security.krb5.internal.ccache.CCacheOutputStream; @@ -389,14 +390,14 @@ // Looks if canonicalized is a longer format of hostName, // we accept cases like // bunny -> bunny.rabbit.hole - if (canonicalized.toLowerCase() - .startsWith(hostName.toLowerCase()+".")) { + if (canonicalized.toLowerCase(Locale.ENGLISH).startsWith( + hostName.toLowerCase(Locale.ENGLISH)+".")) { hostName = canonicalized; } } catch (UnknownHostException e) { // no canonicalization, use old } - nameParts[1] = hostName.toLowerCase(); + nameParts[1] = hostName.toLowerCase(Locale.ENGLISH); } nameStrings = nameParts; nameType = type;
--- a/jdk/src/share/classes/sun/security/pkcs12/PKCS12KeyStore.java Sat Aug 27 15:40:45 2011 +0100 +++ b/jdk/src/share/classes/sun/security/pkcs12/PKCS12KeyStore.java Mon Aug 29 05:55:26 2011 -0700 @@ -219,7 +219,7 @@ public Key engineGetKey(String alias, char[] password) throws NoSuchAlgorithmException, UnrecoverableKeyException { - KeyEntry entry = entries.get(alias.toLowerCase()); + KeyEntry entry = entries.get(alias.toLowerCase(Locale.ENGLISH)); Key key = null; if (entry == null) { @@ -296,7 +296,7 @@ * <i>key entry</i> without a certificate chain). */ public Certificate[] engineGetCertificateChain(String alias) { - KeyEntry entry = entries.get(alias.toLowerCase()); + KeyEntry entry = entries.get(alias.toLowerCase(Locale.ENGLISH)); if (entry != null) { if (entry.chain == null) { return null; @@ -324,7 +324,7 @@ * does not contain a certificate. */ public Certificate engineGetCertificate(String alias) { - KeyEntry entry = entries.get(alias.toLowerCase()); + KeyEntry entry = entries.get(alias.toLowerCase(Locale.ENGLISH)); if (entry != null) { if (entry.chain == null) { return null; @@ -345,7 +345,7 @@ * not exist */ public Date engineGetCreationDate(String alias) { - KeyEntry entry = entries.get(alias.toLowerCase()); + KeyEntry entry = entries.get(alias.toLowerCase(Locale.ENGLISH)); if (entry != null) { return new Date(entry.date.getTime()); } else { @@ -409,10 +409,10 @@ // set the keyId to current date entry.keyId = ("Time " + (entry.date).getTime()).getBytes("UTF8"); // set the alias - entry.alias = alias.toLowerCase(); + entry.alias = alias.toLowerCase(Locale.ENGLISH); // add the entry - entries.put(alias.toLowerCase(), entry); + entries.put(alias.toLowerCase(Locale.ENGLISH), entry); } catch (Exception nsae) { throw new KeyStoreException("Key protection " + " algorithm not found: " + nsae, nsae); @@ -465,7 +465,7 @@ // Won't happen } // set the alias - entry.alias = alias.toLowerCase(); + entry.alias = alias.toLowerCase(Locale.ENGLISH); entry.protectedPrivKey = key.clone(); if (chain != null) { @@ -473,7 +473,7 @@ } // add the entry - entries.put(alias.toLowerCase(), entry); + entries.put(alias.toLowerCase(Locale.ENGLISH), entry); } @@ -618,7 +618,7 @@ public synchronized void engineSetCertificateEntry(String alias, Certificate cert) throws KeyStoreException { - KeyEntry entry = entries.get(alias.toLowerCase()); + KeyEntry entry = entries.get(alias.toLowerCase(Locale.ENGLISH)); if (entry != null) { throw new KeyStoreException("Cannot overwrite own certificate"); } else @@ -635,7 +635,7 @@ public synchronized void engineDeleteEntry(String alias) throws KeyStoreException { - entries.remove(alias.toLowerCase()); + entries.remove(alias.toLowerCase(Locale.ENGLISH)); } /** @@ -655,7 +655,7 @@ * @return true if the alias exists, false otherwise */ public boolean engineContainsAlias(String alias) { - return entries.containsKey(alias.toLowerCase()); + return entries.containsKey(alias.toLowerCase(Locale.ENGLISH)); } /** @@ -675,7 +675,7 @@ * <i>key entry</i>, false otherwise. */ public boolean engineIsKeyEntry(String alias) { - KeyEntry entry = entries.get(alias.toLowerCase()); + KeyEntry entry = entries.get(alias.toLowerCase(Locale.ENGLISH)); if (entry != null) { return true; } else { @@ -1274,7 +1274,8 @@ if (password != null && s.available() > 0) { MacData macData = new MacData(s); try { - String algName = macData.getDigestAlgName().toUpperCase(); + String algName = + macData.getDigestAlgName().toUpperCase(Locale.ENGLISH); if (algName.equals("SHA") || algName.equals("SHA1") || algName.equals("SHA-1")) { @@ -1479,7 +1480,7 @@ if (alias == null) alias = getUnfriendlyName(); entry.alias = alias; - entries.put(alias.toLowerCase(), entry); + entries.put(alias.toLowerCase(Locale.ENGLISH), entry); } else if (bagItem instanceof X509Certificate) { X509Certificate cert = (X509Certificate)bagItem; // Insert a localKeyID for the corresponding cert
--- a/jdk/src/share/classes/sun/security/provider/JavaKeyStore.java Sat Aug 27 15:40:45 2011 +0100 +++ b/jdk/src/share/classes/sun/security/provider/JavaKeyStore.java Mon Aug 29 05:55:26 2011 -0700 @@ -54,7 +54,7 @@ // regular JKS public static final class JKS extends JavaKeyStore { String convertAlias(String alias) { - return alias.toLowerCase(); + return alias.toLowerCase(Locale.ENGLISH); } }
--- a/jdk/src/share/classes/sun/security/provider/certpath/ldap/LDAPCertStore.java Sat Aug 27 15:40:45 2011 +0100 +++ b/jdk/src/share/classes/sun/security/provider/certpath/ldap/LDAPCertStore.java Mon Aug 29 05:55:26 2011 -0700 @@ -879,7 +879,8 @@ if (hashCode == 0) { int result = 17; result = 37*result + getPort(); - result = 37*result + getServerName().toLowerCase().hashCode(); + result = 37*result + + getServerName().toLowerCase(Locale.ENGLISH).hashCode(); hashCode = result; } return hashCode;
--- a/jdk/src/share/classes/sun/security/ssl/SSLSessionContextImpl.java Sat Aug 27 15:40:45 2011 +0100 +++ b/jdk/src/share/classes/sun/security/ssl/SSLSessionContextImpl.java Mon Aug 29 05:55:26 2011 -0700 @@ -33,6 +33,7 @@ import java.util.Hashtable; import java.util.NoSuchElementException; import java.util.Vector; +import java.util.Locale; import javax.net.ssl.SSLSession; import javax.net.ssl.SSLSessionContext; @@ -166,7 +167,8 @@ } private String getKey(String hostname, int port) { - return (hostname + ":" + String.valueOf(port)).toLowerCase(); + return (hostname + ":" + + String.valueOf(port)).toLowerCase(Locale.ENGLISH); } // cache a SSLSession
--- a/jdk/src/share/classes/sun/security/tools/KeyStoreUtil.java Sat Aug 27 15:40:45 2011 +0100 +++ b/jdk/src/share/classes/sun/security/tools/KeyStoreUtil.java Mon Aug 29 05:55:26 2011 -0700 @@ -25,6 +25,8 @@ package sun.security.tools; +import java.util.Locale; + /** * <p> This class provides several utilities to <code>KeyStore</code>. * @@ -63,7 +65,7 @@ } else if(storetype.equalsIgnoreCase("Windows-ROOT")) { return "Windows-ROOT"; } else { - return storetype.toUpperCase(); + return storetype.toUpperCase(Locale.ENGLISH); } } }
--- a/jdk/src/share/classes/sun/security/util/HostnameChecker.java Sat Aug 27 15:40:45 2011 +0100 +++ b/jdk/src/share/classes/sun/security/util/HostnameChecker.java Mon Aug 29 05:55:26 2011 -0700 @@ -266,8 +266,8 @@ */ private static boolean matchAllWildcards(String name, String template) { - name = name.toLowerCase(); - template = template.toLowerCase(); + name = name.toLowerCase(Locale.ENGLISH); + template = template.toLowerCase(Locale.ENGLISH); StringTokenizer nameSt = new StringTokenizer(name, "."); StringTokenizer templateSt = new StringTokenizer(template, "."); @@ -296,8 +296,8 @@ */ private static boolean matchLeftmostWildcard(String name, String template) { - name = name.toLowerCase(); - template = template.toLowerCase(); + name = name.toLowerCase(Locale.ENGLISH); + template = template.toLowerCase(Locale.ENGLISH); // Retreive leftmost component int templateIdx = template.indexOf(".");
--- a/jdk/src/share/classes/sun/security/x509/DNSName.java Sat Aug 27 15:40:45 2011 +0100 +++ b/jdk/src/share/classes/sun/security/x509/DNSName.java Mon Aug 29 05:55:26 2011 -0700 @@ -159,7 +159,7 @@ * @return a hash code value for this object. */ public int hashCode() { - return name.toUpperCase().hashCode(); + return name.toUpperCase(Locale.ENGLISH).hashCode(); } /**
--- a/jdk/src/share/classes/sun/security/x509/RFC822Name.java Sat Aug 27 15:40:45 2011 +0100 +++ b/jdk/src/share/classes/sun/security/x509/RFC822Name.java Mon Aug 29 05:55:26 2011 -0700 @@ -153,7 +153,7 @@ * @return a hash code value for this object. */ public int hashCode() { - return name.toUpperCase().hashCode(); + return name.toUpperCase(Locale.ENGLISH).hashCode(); } /**
--- a/jdk/test/javax/naming/ldap/LdapName/CompareToEqualsTests.java Sat Aug 27 15:40:45 2011 +0100 +++ b/jdk/test/javax/naming/ldap/LdapName/CompareToEqualsTests.java Mon Aug 29 05:55:26 2011 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -23,12 +23,14 @@ /* * @test - * @bug 4635618 + * @bug 4635618 7059542 * @summary Support for manipulating LDAP Names + * JNDI name operations should be locale independent */ import javax.naming.ldap.*; import java.util.ArrayList; +import java.util.Locale; import java.util.List; import javax.naming.InvalidNameException; @@ -39,52 +41,61 @@ public static void main(String args[]) throws Exception { - - /** - * Test cases: - * 1) Same RDNs. - * 2) same RDN sequence with an AVA ordered differently. - * 3) RDN sequences of a differing AVA. - * 4) RDN sequence of different length. - * 5) RDN sequence of different Case. - * 6) Matching binary return values. - * 7) Binary values that don't match. - */ - String names1[] = new String [] { + Locale reservedLocale = Locale.getDefault(); + try { + /** + * Test cases: + * 1) Same RDNs. + * 2) same RDN sequence with an AVA ordered differently. + * 3) RDN sequences of a differing AVA. + * 4) RDN sequence of different length. + * 5) RDN sequence of different Case. + * 6) Matching binary return values. + * 7) Binary values that don't match. + */ + String names1[] = new String [] { "ou=Sales+cn=Bob", "ou=Sales+cn=Bob", "ou=Sales+cn=Bob", "ou=Sales+cn=Scott+c=US", "cn=config"}; - String names2[] = new String [] { + String names2[] = new String [] { "ou=Sales+cn=Bob", "cn=Bob+ou=Sales", "ou=Sales+cn=Scott", "ou=Sales+cn=Scott", "Cn=COnFIG"}; - int expectedResults[] = {0, 0, -1, -1, 0}; + int expectedResults[] = {0, 0, -1, -1, 0}; + for (Locale locale : Locale.getAvailableLocales()) { + // reset the default locale + Locale.setDefault(locale); - for (int i = 0; i < names1.length; i++) { - checkResults(new LdapName(names1[i]), + for (int i = 0; i < names1.length; i++) { + checkResults(new LdapName(names1[i]), new LdapName(names2[i]), expectedResults[i]); + } + + byte[] value = "abcxyz".getBytes(); + Rdn rdn1 = new Rdn("binary", value); + ArrayList rdns1 = new ArrayList(); + rdns1.add(rdn1); + LdapName l1 = new LdapName(rdns1); + + Rdn rdn2 = new Rdn("binary", value); + ArrayList rdns2 = new ArrayList(); + rdns2.add(rdn2); + LdapName l2 = new LdapName(rdns2); + checkResults(l1, l2, 0); + + l2 = new LdapName("binary=#61626378797A"); + checkResults(l1, l2, 0); + + l2 = new LdapName("binary=#61626378797B"); + checkResults(l1, l2, -1); + + System.out.println("Tests passed"); + } + } finally { + // restore the reserved locale + Locale.setDefault(reservedLocale); } - - byte[] value = "abcxyz".getBytes(); - Rdn rdn1 = new Rdn("binary", value); - ArrayList rdns1 = new ArrayList(); - rdns1.add(rdn1); - LdapName l1 = new LdapName(rdns1); - - Rdn rdn2 = new Rdn("binary", value); - ArrayList rdns2 = new ArrayList(); - rdns2.add(rdn2); - LdapName l2 = new LdapName(rdns2); - checkResults(l1, l2, 0); - - l2 = new LdapName("binary=#61626378797A"); - checkResults(l1, l2, 0); - - l2 = new LdapName("binary=#61626378797B"); - checkResults(l1, l2, -1); - - System.out.println("Tests passed"); }