提交 01afc402 编写于 作者: M mchung

8007393: Possible race condition after JDK-6664509

Reviewed-by: alanb, jgish
上级 031a5ed1
...@@ -455,7 +455,40 @@ public class LogManager { ...@@ -455,7 +455,40 @@ public class LogManager {
} }
Logger demandSystemLogger(String name, String resourceBundleName) { 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. // LoggerContext maintains the logger namespace per context.
...@@ -663,21 +696,6 @@ public class LogManager { ...@@ -663,21 +696,6 @@ public class LogManager {
} }
} while (result == null); } 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; return result;
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册