JDK-7067691 : java/lang/management/PlatformLoggingMXBean/LoggingMXBeanTest.java failing intermittently
  • Type: Bug
  • Component: core-svc
  • Sub-Component: java.lang.management
  • Affected Version: 8
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2011-07-15
  • Updated: 2014-02-12
  • Resolved: 2011-11-18
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 7 JDK 8
7u60Fixed 8 b15Fixed
Related Reports
Relates :  
Relates :  
Description
This test failed once, on jprt-sol-sparc-5, with a build of jdk8/tl/jdk that is essentially jdk8-b00 (close to jdk7-b147). 

--------------------------------------------------
TEST: java/lang/management/PlatformLoggingMXBean/LoggingMXBeanTest.java
JDK under test: (/tmp/jprt/P1/100004.ab23780/testproduct/solaris_sparc_5.10-product)
java version "1.8.0-internal"
Java(TM) SE Runtime Environment (build 1.8.0-internal-201107151000.ab23780.jdk-b00)
Java HotSpot(TM) Client VM (build 21.0-b17, mixed mode)

ACTION: build -- Passed. Build successful
REASON: User specified action: run build LoggingMXBeanTest 
TIME:   0.075 seconds
messages:
command: build LoggingMXBeanTest
reason: User specified action: run build LoggingMXBeanTest 
elapsed time (seconds): 0.075

ACTION: compile -- Passed. Compilation successful
REASON: .class file out of date or does not exist
TIME:   0.074 seconds
messages:
command: compile /tmp/jprt/P1/100004.ab23780/source/test/java/lang/management/PlatformLoggingMXBean/LoggingMXBeanTest.java
reason: .class file out of date or does not exist
elapsed time (seconds): 0.074

ACTION: build -- Passed. All files up to date
REASON: Named class compiled on demand
TIME:   0.0 seconds
messages:
command: build LoggingMXBeanTest
reason: Named class compiled on demand
elapsed time (seconds): 0.0

ACTION: main -- Failed. Execution failed: `main' threw exception: java.lang.RuntimeException: LoggerLevel: unmatched level for com.sun.management.Logger.Logger2
REASON: User specified action: run main LoggingMXBeanTest 
TIME:   0.045 seconds
messages:
command: main LoggingMXBeanTest
reason: User specified action: run main LoggingMXBeanTest 
elapsed time (seconds): 0.045
STDOUT:
Test Logger Name retrieval (getLoggerNames)
  : Found new Logger : com.sun.management.Logger.Logger2
  : Found new Logger : com.sun.management.Logger
  : PASSED.
Test getLoggerLevel
  : Level for Logger com.sun.management.Logger : FINE
  : Level for Logger com.sun.management.Logger.Logger2 : 
  : Level for unknown logger : null
Test setLoggerLevel
  : Set Level for Logger com.sun.management.Logger to: INFO
  : Set Level for Logger com.sun.management.Logger.Logger2 to: SERVER
  : Set Level for Logger com.sun.management.Logger to: null
  : Set Level for unknown Logger to: FINE
      : IllegalArgumentException caught as expected
  : Set Level for Logger com.sun.management.Logger to: DUMMY
      : IllegalArgumentException caught as expected
Test getParentLoggerName
  : Parent Logger for com.sun.management.Logger.Logger2 : com.sun.management.Logger
  : Parent Logger for "" : 
  : Parent Logger for unknown logger : null
STDERR:
java.lang.RuntimeException: LoggerLevel: unmatched level for com.sun.management.Logger.Logger2
	at LoggingMXBeanTest.checkAttributes(LoggingMXBeanTest.java:221)
	at LoggingMXBeanTest.main(LoggingMXBeanTest.java:61)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:601)
	at com.sun.javatest.regtest.MainAction$SameVMRunnable.run(MainAction.java:680)
	at java.lang.Thread.run(Thread.java:722)

JavaTest Message: Test threw exception: java.lang.RuntimeException
JavaTest Message: shutting down test


TEST RESULT: Failed. Execution failed: `main' threw exception: java.lang.RuntimeException: LoggerLevel: unmatched level for com.sun.management.Logger.Logger2
--------------------------------------------------
Similar/same problem in:

    java/lang/management/PlatformLoggingMXBean/PlatformLoggingMXBeanTest.java

Comments
EVALUATION Similar fix was applied to PlatformLoggingMXBeanTest.
18-11-2011

EVALUATION By adding a call to System.gc() before the call to checkAttributes() the failure can be seen directly. Using static references the loggers can be blocked form unexpected garbage collection.
08-11-2011

SUGGESTED FIX Here's an updated proposed fix. diff --git a/test/java/lang/management/PlatformLoggingMXBean/LoggingMXBeanTest.java b/test/java/lang/management/PlatformLoggingMXBean/LoggingMXBeanTest.java --- a/test/java/lang/management/PlatformLoggingMXBean/LoggingMXBeanTest.java +++ b/test/java/lang/management/PlatformLoggingMXBean/LoggingMXBeanTest.java @@ -42,6 +42,9 @@ static String LOGGER_NAME_1 = "com.sun.management.Logger"; static String LOGGER_NAME_2 = "com.sun.management.Logger.Logger2"; static String UNKNOWN_LOGGER_NAME = "com.sun.management.Unknown"; + static Logger logger1; + static Logger logger2; + static LoggingMXBeanTest testp; public static void main(String[] argv) throws Exception { MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); @@ -51,7 +54,7 @@ LoggingMXBean.class); // test LoggingMXBean proxy - LoggingMXBeanTest p = new LoggingMXBeanTest(proxy); + testp = new LoggingMXBeanTest(proxy); // check if the attributes implemented by PlatformLoggingMXBean // and LoggingMXBean return the same value @@ -59,14 +62,18 @@ ManagementFactory.getPlatformMXBean(mbs, PlatformLoggingMXBean.class); checkAttributes(proxy, mxbean); + + logger1 = null; + logger2 = null; + testp = null; } // same verification as in java/util/logging/LoggingMXBeanTest2 public LoggingMXBeanTest(LoggingMXBean mbean) throws Exception { - Logger logger1 = Logger.getLogger( LOGGER_NAME_1 ); + logger1 = Logger.getLogger( LOGGER_NAME_1 ); logger1.setLevel(Level.FINE); - Logger logger2 = Logger.getLogger( LOGGER_NAME_2 ); + logger2 = Logger.getLogger( LOGGER_NAME_2 ); logger2.setLevel(null); /* @@ -207,6 +214,18 @@ // verify logger names List<String> loggers1 = mxbean1.getLoggerNames(); List<String> loggers2 = mxbean2.getLoggerNames(); + + // Print the two logger lists for diagnostic purposes + System.out.println(" : LoggingMXBean " + loggers1); + System.out.println(" : PlatformLoggingMXBean " + loggers2); + + // Print the list of logger level comparisons for diagnostic purposes + for (String logger : loggers1) { + System.out.println (" : Level (" + logger + + ", " + mxbean1.getLoggerLevel(logger) + + ", " + mxbean2.getLoggerLevel(logger) + ")"); + } + if (loggers1.size() != loggers2.size()) throw new RuntimeException("LoggerNames: unmatched number of entries"); List<String> loggers3 = new ArrayList<>(loggers1); @@ -219,7 +238,10 @@ if (!mxbean1.getLoggerLevel(logger) .equals(mxbean2.getLoggerLevel(logger))) throw new RuntimeException( - "LoggerLevel: unmatched level for " + logger); + "LoggerLevel: unmatched level for (" + logger + + ", " + mxbean1.getLoggerLevel(logger) + + ", " + mxbean2.getLoggerLevel(logger) + ")"); + if (!mxbean1.getParentLoggerName(logger) .equals(mxbean2.getParentLoggerName(logger))) throw new RuntimeException(
08-11-2011

EVALUATION I've annotated a copy of the test with some notes indicating the failure path taken by the test and some notes showing where things can be GC'ed. *** LoggingMXBeanTest.java.orig Fri Jul 15 14:16:12 2011 --- LoggingMXBeanTest.java.notes Fri Jul 15 14:23:12 2011 *************** *** 50,73 **** --- 50,78 ---- LogManager.LOGGING_MXBEAN_NAME, LoggingMXBean.class); // test LoggingMXBean proxy LoggingMXBeanTest p = new LoggingMXBeanTest(proxy); + // There's no use of 'p' after this point. It can be GCed + // along with the local Logger objects. // check if the attributes implemented by PlatformLoggingMXBean // and LoggingMXBean return the same value PlatformLoggingMXBean mxbean = ManagementFactory.getPlatformMXBean(mbs, PlatformLoggingMXBean.class); + // This checkAttributes() call throws the exception checkAttributes(proxy, mxbean); } // same verification as in java/util/logging/LoggingMXBeanTest2 public LoggingMXBeanTest(LoggingMXBean mbean) throws Exception { + // logger1 created as a local here Logger logger1 = Logger.getLogger( LOGGER_NAME_1 ); logger1.setLevel(Level.FINE); + // logger2 created as a local here Logger logger2 = Logger.getLogger( LOGGER_NAME_2 ); logger2.setLevel(null); /* * Check for the existence of our new Loggers *************** *** 132,150 **** --- 137,157 ---- } mbean.setLoggerLevel(LOGGER_NAME_2, "SEVERE"); System.out.println(" : Set Level for Logger " + LOGGER_NAME_2 + " to: SERVER"); l = logger2.getLevel(); + // there's no use of logger2 after this point; it can be GC'ed if (l != Level.SEVERE) { throw new RuntimeException( "Expected level for " + LOGGER_NAME_2 + " = " + Level.SEVERE+ " but got " + l); } mbean.setLoggerLevel(LOGGER_NAME_1, null); System.out.println(" : Set Level for Logger " + LOGGER_NAME_1 + " to: null"); l = logger1.getLevel(); + // there's no use of logger1 after this point; it can be GC'ed if (l != null) { throw new RuntimeException( "Expected level for " + LOGGER_NAME_1 + " = null " + " but got " + l); } *************** *** 216,225 **** --- 223,233 ---- // verify logger's level and parent for (String logger : loggers1) { if (!mxbean1.getLoggerLevel(logger) .equals(mxbean2.getLoggerLevel(logger))) + // test throws this exception: throw new RuntimeException( "LoggerLevel: unmatched level for " + logger); if (!mxbean1.getParentLoggerName(logger) .equals(mxbean2.getParentLoggerName(logger))) throw new RuntimeException( The Loggers in this test need to be static variables in the LoggingMXBeanTest class just like the names of the Loggers. Please see the following two Logger bugs: 6274920 4/2 JDK logger holds strong reference to java.util.logging.Logger instances 6949710 3/3 the GC'able nature of Logging objects needs to be made brutally clear
15-07-2011