changeset 5888:d00ab6592b1e

Merge
author michaelm
date Wed, 13 Feb 2013 10:50:09 +0000
parents 7ca8a40795d8 b6645161a51b
children 3e2d47699a54 e9e8c27a8e3e
files
diffstat 2 files changed, 42 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/.hgtags	Wed Feb 13 10:47:15 2013 +0000
+++ b/.hgtags	Wed Feb 13 10:50:09 2013 +0000
@@ -232,4 +232,8 @@
 ee61b528b3f866b20095f5e9593896d4ea4be468 jdk7u11-b08
 0b9564dab118d40bc5edc60269f736f97ab6f385 jdk7u13-b09
 cbbb166b38eb15f5d5c68e913ee18f6f352b7af0 jdk7u13-b10
+28700a56b69d80e70aecf230ab7f9ad4bb5acf23 jdk7u13-b30
+8eb180a284b0911b2645d5cbdff5be499a75d6b2 jdk7u13-b20
+835448d525a10bb826f4f7ebe272fc410bdb0f5d jdk7u15-b01
+0443fe2d8023111b52f4c8db32e038f4a5a9f373 jdk7u15-b02
 8261e56b7f91c7553e8485b206bdc9030a3546e4 jdk7u21-b01
--- a/src/share/classes/java/util/logging/LogManager.java	Wed Feb 13 10:47:15 2013 +0000
+++ b/src/share/classes/java/util/logging/LogManager.java	Wed Feb 13 10:50:09 2013 +0000
@@ -363,7 +363,10 @@
                         context = userContext;
                     } else {
                         context = new LoggerContext();
-                        context.addLocalLogger(manager.rootLogger);
+                        // during initialization, rootLogger is null when
+                        // instantiating itself RootLogger
+                        if (manager.rootLogger != null)
+                            context.addLocalLogger(manager.rootLogger);
                     }
                     javaAwtAccess.put(ecx, LoggerContext.class, context);
                 }
@@ -423,7 +426,40 @@
     }
 
     Logger demandSystemLogger(String name, String resourceBundleName) {
-        return systemContext.demandLogger(name, resourceBundleName);
+        // Add a system logger in the system context's namespace
+        final Logger sysLogger = systemContext.demandLogger(name, resourceBundleName);
+
+        // Add the system logger to the LogManager's namespace if not exist
+        // so that there is only one single logger of the given name.
+        // System loggers are visible to applications unless a logger of
+        // the same name has been added.
+        Logger logger;
+        do {
+            // First attempt to call addLogger instead of getLogger
+            // This would avoid potential bug in custom LogManager.getLogger
+            // implementation that adds a logger if does not exist
+            if (addLogger(sysLogger)) {
+                // successfully added the new system logger
+                logger = sysLogger;
+            } else {
+                logger = getLogger(name);
+            }
+        } while (logger == null);
+
+        // LogManager will set the sysLogger's handlers via LogManager.addLogger method.
+        if (logger != sysLogger && sysLogger.getHandlers().length == 0) {
+            // if logger already exists but handlers not set
+            final Logger l = logger;
+            AccessController.doPrivileged(new PrivilegedAction<Void>() {
+                public Void run() {
+                    for (Handler hdl : l.getHandlers()) {
+                        sysLogger.addHandler(hdl);
+                    }
+                    return null;
+                }
+            });
+        }
+        return sysLogger;
     }
 
     // LoggerContext maintains the logger namespace per context.
@@ -628,21 +664,6 @@
                     }
                 } while (result == null);
             }
-            // Add the system logger to the LogManager's namespace if not exists
-            // The LogManager will set its handlers via the LogManager.addLogger method.
-            if (!manager.addLogger(result) && result.getHandlers().length == 0) {
-                // if logger already exists but handlers not set
-                final Logger l = manager.getLogger(name);
-                final Logger logger = result;
-                AccessController.doPrivileged(new PrivilegedAction<Void>() {
-                    public Void run() {
-                        for (Handler hdl : l.getHandlers()) {
-                            logger.addHandler(hdl);
-                        }
-                        return null;
-                    }
-                });
-            }
             return result;
         }
     }