changeset 3226:01b6d147db50

6527572: (cs) Charset.forName can throw NullPointerException when testing bug level Summary: fixed the race condition Reviewed-by: alanb
author sherman
date Wed, 08 Dec 2010 12:15:55 -0800
parents acce526a49a7
children 956de70712e0
files src/share/classes/java/nio/charset/Charset.java
diffstat 1 files changed, 6 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/java/nio/charset/Charset.java	Wed Dec 08 10:45:28 2010 -0800
+++ b/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);
     }
 
     /**