6527572: (cs) Charset.forName can throw NullPointerException when testing bug level
Summary: fixed the race condition
Reviewed-by: alanb
--- 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);
}
/**