7153184: NullPointerException when calling SSLEngineImpl.getSupportedCipherSuites
authorxuelei
Fri, 04 May 2012 17:28:27 -0700
changeset 12671 729f78ba3a10
parent 12670 6cf9bd9a9302
child 12672 6daea025e1dd
7153184: NullPointerException when calling SSLEngineImpl.getSupportedCipherSuites Reviewed-by: weijun
jdk/src/share/classes/sun/security/ssl/SSLContextImpl.java
--- a/jdk/src/share/classes/sun/security/ssl/SSLContextImpl.java	Fri May 04 16:00:47 2012 -0400
+++ b/jdk/src/share/classes/sun/security/ssl/SSLContextImpl.java	Fri May 04 17:28:27 2012 -0700
@@ -267,12 +267,15 @@
 
     // Get suported CipherSuiteList.
     CipherSuiteList getSuportedCipherSuiteList() {
-        // Clear cache of available ciphersuites.
-        clearAvailableCache();
+        // The maintenance of cipher suites needs to be synchronized.
+        synchronized (this) {
+            // Clear cache of available ciphersuites.
+            clearAvailableCache();
 
-        if (supportedCipherSuiteList == null) {
-            supportedCipherSuiteList =
-                getApplicableCipherSuiteList(getSuportedProtocolList(), false);
+            if (supportedCipherSuiteList == null) {
+                supportedCipherSuiteList = getApplicableCipherSuiteList(
+                        getSuportedProtocolList(), false);
+            }
         }
 
         return supportedCipherSuiteList;
@@ -280,20 +283,29 @@
 
     // Get default CipherSuiteList.
     CipherSuiteList getDefaultCipherSuiteList(boolean roleIsServer) {
-        // Clear cache of available ciphersuites.
-        clearAvailableCache();
+        if (roleIsServer) {
+            // The maintenance of cipher suites needs to be synchronized.
+            synchronized (this) {
+                // Clear cache of available ciphersuites.
+                clearAvailableCache();
 
-        if (roleIsServer) {
-            if (defaultServerCipherSuiteList == null) {
-                defaultServerCipherSuiteList = getApplicableCipherSuiteList(
+                if (defaultServerCipherSuiteList == null) {
+                    defaultServerCipherSuiteList = getApplicableCipherSuiteList(
                         getDefaultProtocolList(true), true);
+                }
             }
 
             return defaultServerCipherSuiteList;
         } else {
-            if (defaultClientCipherSuiteList == null) {
-                defaultClientCipherSuiteList = getApplicableCipherSuiteList(
+            // The maintenance of cipher suites needs to be synchronized
+            synchronized (this) {
+                // Clear cache of available ciphersuites.
+                clearAvailableCache();
+
+                if (defaultClientCipherSuiteList == null) {
+                    defaultClientCipherSuiteList = getApplicableCipherSuiteList(
                         getDefaultProtocolList(false), true);
+                }
             }
 
             return defaultClientCipherSuiteList;
@@ -364,8 +376,11 @@
      * Clear cache of available ciphersuites. If we support all ciphers
      * internally, there is no need to clear the cache and calling this
      * method has no effect.
+     *
+     * Note that every call to clearAvailableCache() and the maintenance of
+     * cipher suites need to be synchronized with this instance.
      */
-    synchronized void clearAvailableCache() {
+    private void clearAvailableCache() {
         if (CipherSuite.DYNAMIC_AVAILABILITY) {
             supportedCipherSuiteList = null;
             defaultServerCipherSuiteList = null;