-
Bug
-
Resolution: Fixed
-
P4
-
11, 12, 13
-
b16
-
generic
-
generic
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8228933 | 12u-cpu | Steve Groeger | P4 | Resolved | Fixed | master |
JDK-8223129 | 12.0.2 | Steve Groeger | P4 | Resolved | Fixed | b03 |
JDK-8235287 | 11.0.7-oracle | Ivan Gerasimov | P4 | Resolved | Fixed | b01 |
JDK-8223023 | 11.0.4 | Steve Groeger | P4 | Resolved | Fixed | b01 |
The test java/util/logging/LogManager/TestLoggerNames.java generates intermittent ClassCastException following some garbage collection.
Here is the test code snippet from TestLoggerNames.java:
LogManager.getLogManager().addLogger(new TestLogger("com.foo.bar.zzz", null));
...
TestLogger test = (TestLogger)Logger.getLogger("com.foo.bar.zzz"); --> j.l.ClassCastException here
As per Java doc java.util.logging.LogManager.addLogger():
```
The application should retain its own reference to the Logger object to avoid it being garbage collected. The LogManager may only retain a weak reference.
```
Java doc for java.util.logging.Logger.getLogger():
```
Find or create a logger for a named subsystem. If a logger has already been created with the given name it is returned. Otherwise a new logger is created.
```
Here is how a java.lang.ClassCastException happened:
1) LogManager added a new TestLogger("com.foo.bar.zzz") which is a subclass of java.util.logging.Logger;
2) GC was triggered and collected the newly added TestLogger instance;
3)Logger.getLogger("com.foo.bar.zzz") can't find a logger for the name com.foo.bar.zzz hence creates a new logger which is an instance of java.util.logging.Logger, then ClassCastException is thrown when the test attempts to cast the return instance to TestLogger.
If the TestLogger("com.foo.bar.zzz") instance wasn't collected by GC, Logger.getLogger("com.foo.bar.zzz") can retrieve it successfully and the test passes.
This was consistently recreated in a simple test case by adding explicit System.gc() call between the TestLogger being added and retrieved from the LogManager, the ClassCastException is thrown consistently.
Here is the test code snippet from TestLoggerNames.java:
LogManager.getLogManager().addLogger(new TestLogger("com.foo.bar.zzz", null));
...
TestLogger test = (TestLogger)Logger.getLogger("com.foo.bar.zzz"); --> j.l.ClassCastException here
As per Java doc java.util.logging.LogManager.addLogger():
```
The application should retain its own reference to the Logger object to avoid it being garbage collected. The LogManager may only retain a weak reference.
```
Java doc for java.util.logging.Logger.getLogger():
```
Find or create a logger for a named subsystem. If a logger has already been created with the given name it is returned. Otherwise a new logger is created.
```
Here is how a java.lang.ClassCastException happened:
1) LogManager added a new TestLogger("com.foo.bar.zzz") which is a subclass of java.util.logging.Logger;
2) GC was triggered and collected the newly added TestLogger instance;
3)Logger.getLogger("com.foo.bar.zzz") can't find a logger for the name com.foo.bar.zzz hence creates a new logger which is an instance of java.util.logging.Logger, then ClassCastException is thrown when the test attempts to cast the return instance to TestLogger.
If the TestLogger("com.foo.bar.zzz") instance wasn't collected by GC, Logger.getLogger("com.foo.bar.zzz") can retrieve it successfully and the test passes.
This was consistently recreated in a simple test case by adding explicit System.gc() call between the TestLogger being added and retrieved from the LogManager, the ClassCastException is thrown consistently.
- backported by
-
JDK-8223023 TEST_BUG: java/util/logging/LogManager/TestLoggerNames.java generates intermittent ClassCastException
- Resolved
-
JDK-8223129 TEST_BUG: java/util/logging/LogManager/TestLoggerNames.java generates intermittent ClassCastException
- Resolved
-
JDK-8228933 TEST_BUG: java/util/logging/LogManager/TestLoggerNames.java generates intermittent ClassCastException
- Resolved
-
JDK-8235287 TEST_BUG: java/util/logging/LogManager/TestLoggerNames.java generates intermittent ClassCastException
- Resolved