# HG changeset patch # User mchung # Date 1360133807 28800 # Node ID 5c5fc1d5bb388e0dd8ab71163f57858341038d7c # Parent 2ce1c415475b5cb263df93523a796ce4db6ff082 8007393: Possible race condition after JDK-6664509 Reviewed-by: alanb, jgish diff -r 2ce1c415475b -r 5c5fc1d5bb38 jdk/src/share/classes/java/util/logging/LogManager.java --- a/jdk/src/share/classes/java/util/logging/LogManager.java Thu Jan 24 16:45:38 2013 -0800 +++ b/jdk/src/share/classes/java/util/logging/LogManager.java Tue Feb 05 22:56:47 2013 -0800 @@ -455,7 +455,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() { + public Void run() { + for (Handler hdl : l.getHandlers()) { + sysLogger.addHandler(hdl); + } + return null; + } + }); + } + return sysLogger; } // LoggerContext maintains the logger namespace per context. @@ -663,21 +696,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() { - public Void run() { - for (Handler hdl : l.getHandlers()) { - logger.addHandler(hdl); - } - return null; - } - }); - } return result; } }