Johannes Schleger created LOG4J2-1506:
-----------------------------------------

             Summary: Unregister JMX ignores log4j2.disable.jmx property
                 Key: LOG4J2-1506
                 URL: https://issues.apache.org/jira/browse/LOG4J2-1506
             Project: Log4j 2
          Issue Type: Bug
          Components: JMX
    Affects Versions: 2.6.2
         Environment: Stripped OpenJDK (without java.lang.management)
            Reporter: Johannes Schleger


If java.lang.management is due to security reasons (or anything else) not part 
of the JVM, we need so set the JVM Property -Dlog4j2.jmx.disable=true.

The initialization of the JVM is fine, as the JMX Server class verifies if JMX 
is disabled. The Problem is as soon as log4j shuts down, it tries to unregister 
JMX and ends up with a NoClassDefFoundError, thus log4j 

{code:title=Server.java|borderStyle=solid}
public static void reregisterMBeansAfterReconfigure() {
        // avoid creating Platform MBean Server if JMX disabled
        if (isJmxDisabled()) {
            LOGGER.debug("JMX disabled for log4j2. Not registering MBeans.");
            return;
        }
        final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
        reregisterMBeansAfterReconfigure(mbs);
    }

    public static void unregisterLoggerContext(final String loggerContextName) {
        final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
        unregisterLoggerContext(loggerContextName, mbs);
    }
{code}


{code:java}
2016-08-09 18:54:06,512 pool-1-thread-1 ERROR Caught exception executing 
shutdown hook Shutdown callback for LoggerContext[name=4ee00c09] 
java.lang.NoClassDefFoundError: java/lang/management/ManagementFactory
        at 
org.apache.logging.log4j.core.jmx.Server.unregisterLoggerContext(Server.java:236)
        at 
org.apache.logging.log4j.core.LoggerContext.stop(LoggerContext.java:300)
        at 
org.apache.logging.log4j.core.LoggerContext$1.run(LoggerContext.java:265)
        at 
org.apache.logging.log4j.core.util.DefaultShutdownCallbackRegistry$RegisteredCancellable.run(DefaultShutdownCallbackRegistry.java:102)
        at 
org.apache.logging.log4j.core.util.DefaultShutdownCallbackRegistry.run(DefaultShutdownCallbackRegistry.java:72)
        at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.ClassNotFoundException: 
java.lang.management.ManagementFactory
        at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
        ... 6 more
    }
{code}





--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to