[
https://issues.apache.org/jira/browse/LOG4J2-396?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13759627#comment-13759627
]
Abhinav Shah commented on LOG4J2-396:
-------------------------------------
I am running this application from Eclipse -> Run as Java application.
Here is the source code of the java program -
{code}
package com.labcorp.eag.junit;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class TestConsoleApp {
private static final Logger LOGGER =
LoggerFactory.getLogger(TestConsoleApp.class);
public static void main(String[] args) {
LOGGER.info("Hello World");
}
}
{code}
Stack Trace -
{code}
java.lang.IllegalAccessError: tried to access method
javax.management.StandardMBean.<init>(Ljava/lang/Object;Ljava/lang/Class;Z)V
from class sun.management.ManagementFactory
at
sun.management.ManagementFactory.addMXBean(ManagementFactory.java:249)
at
sun.management.ManagementFactory.createPlatformMBeanServer(ManagementFactory.java:304)
at
java.lang.management.ManagementFactory.getPlatformMBeanServer(ManagementFactory.java:504)
at
org.apache.logging.log4j.core.jmx.Server.registerMBeans(Server.java:107)
at
org.apache.logging.log4j.core.impl.Log4jContextFactory.<init>(Log4jContextFactory.java:59)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at java.lang.Class.newInstance0(Class.java:355)
at java.lang.Class.newInstance(Class.java:308)
at org.apache.logging.log4j.LogManager.<clinit>(LogManager.java:85)
at
org.slf4j.helpers.Log4jLoggerFactory.getContext(Log4jLoggerFactory.java:90)
at
org.slf4j.helpers.Log4jLoggerFactory.getLogger(Log4jLoggerFactory.java:46)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:270)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:281)
at com.labcorp.eag.junit.TestConsoleApp.<clinit>(TestConsoleApp.java:7)
Exception in thread "main"
{code}
> Disable JMX by default
> ----------------------
>
> Key: LOG4J2-396
> URL: https://issues.apache.org/jira/browse/LOG4J2-396
> Project: Log4j 2
> Issue Type: Improvement
> Components: JMX
> Affects Versions: 2.0-beta8
> Reporter: Abhinav Shah
>
> Shouldn't we disable JMX by default?
> I see currently in Log4jContextFactory, the MBeans are being registered by
> default -
> {code}
> public Log4jContextFactory() {
> final String sel =
> PropertiesUtil.getProperties().getStringProperty(Constants.LOG4J_CONTEXT_SELECTOR);
> if (sel != null) {
> try {
> final Class<?> clazz = Loader.loadClass(sel);
> if (clazz != null &&
> ContextSelector.class.isAssignableFrom(clazz)) {
> selector = (ContextSelector) clazz.newInstance();
> }
> } catch (final Exception ex) {
> LOGGER.error("Unable to create context " + sel, ex);
> }
> }
> if (selector == null) {
> selector = new ClassLoaderContextSelector();
> }
> try {
> Server.registerMBeans(selector);
> } catch (final Exception ex) {
> LOGGER.error("Could not start JMX", ex);
> }
> }
> {code}
> The is causing errors in my standalone java application which is a simple
> console utility.
> I am getting the following error as Log4j tries to register MBeans -
> {code}
> java.lang.IllegalAccessError: tried to access method
> javax.management.StandardMBean.<init>(Ljava/lang/Object;Ljava/lang/Class;Z)V
> from class sun.management.ManagementFactory
> at
> sun.management.ManagementFactory.addMXBean(ManagementFactory.java:249)
> at
> sun.management.ManagementFactory.createPlatformMBeanServer(ManagementFactory.java:304)
> at
> java.lang.management.ManagementFactory.getPlatformMBeanServer(ManagementFactory.java:504)
> at
> org.apache.logging.log4j.core.jmx.Server.registerMBeans(Server.java:107)
> at
> org.apache.logging.log4j.core.impl.Log4jContextFactory.<init>(Log4jContextFactory.java:59)
> at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
> at
> sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
> at
> sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
> at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
> at java.lang.Class.newInstance0(Class.java:355)
> at java.lang.Class.newInstance(Class.java:308)
> at org.apache.logging.log4j.LogManager.<clinit>(LogManager.java:85)
> at
> org.slf4j.helpers.Log4jLoggerFactory.getContext(Log4jLoggerFactory.java:90)
> at
> org.slf4j.helpers.Log4jLoggerFactory.getLogger(Log4jLoggerFactory.java:46)
> at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:270)
> at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:281)
> at
> com.labcorp.eag.util.jms.SaveQueueToFiles.<clinit>(SaveQueueToFiles.java:45)
> Exception in thread "main"
> {code}
> Currently I overcome this error by setting
> {code}
> -Dlog4j2.disable.jmx=true
> {code}
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]