6527572: (cs) Charset.forName can throw NullPointerException when testing bug level
authorsherman
Wed, 08 Dec 2010 12:15:55 -0800 (2010-12-08)
changeset 7541 f7a5cde8d213
parent 7540 df3383a0e30d
child 7542 514d58003c20
6527572: (cs) Charset.forName can throw NullPointerException when testing bug level Summary: fixed the race condition Reviewed-by: alanb
jdk/src/share/classes/java/nio/charset/Charset.java
--- a/jdk/src/share/classes/java/nio/charset/Charset.java	Wed Dec 08 10:45:28 2010 -0800
+++ b/jdk/src/share/classes/java/nio/charset/Charset.java	Wed Dec 08 12:15:55 2010 -0800
@@ -275,18 +275,17 @@
 
     /* -- Static methods -- */
 
-    private static String bugLevel = null;
+    private static volatile String bugLevel = null;
 
     static boolean atBugLevel(String bl) {              // package-private
-        if (bugLevel == null) {
+        String level = bugLevel;
+        if (level == null) {
             if (!sun.misc.VM.isBooted())
                 return false;
-            bugLevel = AccessController.doPrivileged(
-                new GetPropertyAction("sun.nio.cs.bugLevel"));
-            if (bugLevel == null)
-                bugLevel = "";
+            bugLevel = level = AccessController.doPrivileged(
+                new GetPropertyAction("sun.nio.cs.bugLevel", ""));
         }
-        return (bugLevel != null) && bugLevel.equals(bl);
+        return level.equals(bl);
     }
 
     /**