diff options
author | Sascha Brawer <brawer@dandelis.ch> | 2002-12-17 10:16:44 +0000 |
---|---|---|
committer | Sascha Brawer <brawer@dandelis.ch> | 2002-12-17 10:16:44 +0000 |
commit | 0ee0ab24c4476c988daf98174c330977018a2a7e (patch) | |
tree | 01675cf7a82dec1db4dd427cad92405772bf9f12 | |
parent | 321a10d5dde20b1f7464e7bddafaa3f2f9585f3e (diff) | |
download | classpath-0ee0ab24c4476c988daf98174c330977018a2a7e.tar.gz |
Fix a dependency on the order in which the JVM chooses to initialize
the mutually dependent classes java.util.logging.LogManager and
java.util.logging.Logger.
Thanks to Sergio Freire <sergio-s-freire@ptinovacao.pt> for reporting
the bug which would only occur on GCJ 3.2, not on the Sun 1.3.1 JVM.
-rw-r--r-- | java/util/logging/LogManager.java | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/java/util/logging/LogManager.java b/java/util/logging/LogManager.java index 6e4bf5c6e..80df7a385 100644 --- a/java/util/logging/LogManager.java +++ b/java/util/logging/LogManager.java @@ -141,19 +141,31 @@ public class LogManager protected LogManager() { if (logManager != null) - throw new IllegalStateException("there can be only one LogManager; use LogManager.getLogManager()"); + throw new IllegalStateException( + "there can be only one LogManager; use LogManager.getLogManager()"); logManager = this; loggers = new java.util.HashMap(); rootLogger = new Logger("", null); addLogger(rootLogger); - - /* Logger.global is set during class initialization of Logger, - * which can be before the root logger has been created. Make - * sure that the global logger always has the root logger as - * its parent. + + /* Make sure that Logger.global has the rootLogger as its parent. + * + * Logger.global is set during class initialization of Logger, + * which may or may not be before this code is being executed. + * For example, on the Sun 1.3.1 and 1.4.0 JVMs, Logger.global + * has been set before this code is being executed. In contrast, + * Logger.global still is null on GCJ 3.2. Since the LogManager + * and Logger classes are mutually dependent, both behaviors are + * correct. + * + * This means that we cannot depend on Logger.global to have its + * value when this code executes, although that variable is final. + * Since Logger.getLogger will always return the same logger for + * the same name, the subsequent line works fine irrespective of + * the order in which classes are initialized. */ - Logger.global.setParent(rootLogger); + Logger.getLogger("global").setParent(rootLogger); } |