7063647: To use synchronized map in key manager
authorxuelei
Mon, 15 Aug 2011 00:30:35 -0700
changeset 10334 26b816b3f236
parent 10333 96264d6bb3a3
child 10335 3c7eda3ab2f5
7063647: To use synchronized map in key manager Reviewed-by: wetmore, weijun
jdk/src/share/classes/sun/security/ssl/SunX509KeyManagerImpl.java
--- a/jdk/src/share/classes/sun/security/ssl/SunX509KeyManagerImpl.java	Mon Aug 15 11:43:09 2011 +0800
+++ b/jdk/src/share/classes/sun/security/ssl/SunX509KeyManagerImpl.java	Mon Aug 15 00:30:35 2011 -0700
@@ -84,7 +84,7 @@
      *
      * Map: String(keyType) -> String[](alias)
      */
-    private Map<String,String[]> serverAliasCache;
+    private final Map<String,String[]> serverAliasCache;
 
     /*
      * Basic container for credentials implemented as an inner class.
@@ -113,11 +113,13 @@
         }
     }
 
-    SunX509KeyManagerImpl(KeyStore ks, char[] password) throws KeyStoreException,
+    SunX509KeyManagerImpl(KeyStore ks, char[] password)
+            throws KeyStoreException,
             NoSuchAlgorithmException, UnrecoverableKeyException {
 
         credentialsMap = new HashMap<String,X509Credentials>();
-        serverAliasCache = new HashMap<String,String[]>();
+        serverAliasCache = Collections.synchronizedMap(
+                            new HashMap<String,String[]>());
         if (ks == null) {
             return;
         }
@@ -352,15 +354,17 @@
             if (sigType != null) {
                 if (certs.length > 1) {
                     // if possible, check the public key in the issuer cert
-                    if (!sigType.equals(certs[1].getPublicKey().getAlgorithm())) {
+                    if (!sigType.equals(
+                            certs[1].getPublicKey().getAlgorithm())) {
                         continue;
                     }
                 } else {
                     // Check the signature algorithm of the certificate itself.
                     // Look for the "withRSA" in "SHA1withRSA", etc.
                     String sigAlgName =
-                            certs[0].getSigAlgName().toUpperCase(Locale.ENGLISH);
-                    String pattern = "WITH" + sigType.toUpperCase(Locale.ENGLISH);
+                        certs[0].getSigAlgName().toUpperCase(Locale.ENGLISH);
+                    String pattern = "WITH" +
+                        sigType.toUpperCase(Locale.ENGLISH);
                     if (sigAlgName.contains(pattern) == false) {
                         continue;
                     }
@@ -412,5 +416,4 @@
         }
         return list.toArray(new X500Principal[list.size()]);
     }
-
 }