Description
We have a custom OSGi based application. We specify Log4jContextSelector=org.apache.logging.log4j.core.selector.BasicContextSelector. We initialize log4j through
Configurator.initialize("main", logConfigPath);
Starting from log4j2 2.7 above line fails due to NPE/ExceptionInInitializerError in LogManager static init block. I found a work around by specifying disableThreadContextMap=true. This is 2.7 specific change.
Exception in thread "main" java.lang.ExceptionInInitializerError at org.apache.logging.log4j.ThreadContextAccess.getThreadContextMap(ThreadContextAccess.java:45) at org.apache.logging.log4j.core.impl.ContextDataInjectorFactory.createDefaultInjector(ContextDataInjectorFactory.java:83) at org.apache.logging.log4j.core.impl.ContextDataInjectorFactory.createInjector(ContextDataInjectorFactory.java:67) at org.apache.logging.log4j.core.lookup.ContextMapLookup.<init>(ContextMapLookup.java:34) at org.apache.logging.log4j.core.lookup.Interpolator.<init>(Interpolator.java:116) at org.apache.logging.log4j.core.config.AbstractConfiguration.<init>(AbstractConfiguration.java:120) at org.apache.logging.log4j.core.config.NullConfiguration.<init>(NullConfiguration.java:32) at org.apache.logging.log4j.core.LoggerContext.<clinit>(LoggerContext.java:72) at org.apache.logging.log4j.core.selector.BasicContextSelector.<clinit>(BasicContextSelector.java:32) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:422) at org.apache.logging.log4j.util.LoaderUtil.newInstanceOf(LoaderUtil.java:158) at org.apache.logging.log4j.util.LoaderUtil.newInstanceOf(LoaderUtil.java:180) at org.apache.logging.log4j.util.LoaderUtil.newCheckedInstanceOf(LoaderUtil.java:201) at org.apache.logging.log4j.util.LoaderUtil.newCheckedInstanceOfProperty(LoaderUtil.java:226) at org.apache.logging.log4j.core.impl.Log4jContextFactory.createContextSelector(Log4jContextFactory.java:97) at org.apache.logging.log4j.core.impl.Log4jContextFactory.<init>(Log4jContextFactory.java:58) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:422) at java.lang.Class.newInstance(Class.java:442) at org.apache.logging.log4j.LogManager.<clinit>(LogManager.java:94) at org.apache.logging.log4j.core.config.Configurator.getFactory(Configurator.java:46) at org.apache.logging.log4j.core.config.Configurator.initialize(Configurator.java:157) at org.apache.logging.log4j.core.config.Configurator.initialize(Configurator.java:131) at org.apache.logging.log4j.core.config.Configurator.initialize(Configurator.java:101) at org.apache.logging.log4j.core.config.Configurator.initialize(Configurator.java:188) at com.tradingscreen.client.tradesmart.OSGiMain.initLogging(OSGiMain.java:264) at com.tradingscreen.client.tradesmart.OSGiMain.main(OSGiMain.java:86) Caused by: java.lang.NullPointerException at org.apache.logging.log4j.spi.ThreadContextMapFactory.createThreadContextMap(ThreadContextMapFactory.java:59) at org.apache.logging.log4j.ThreadContext.init(ThreadContext.java:222) at org.apache.logging.log4j.ThreadContext.<clinit>(ThreadContext.java:201) ... 32 more
Attachments
Issue Links
- is related to
-
LOG4J2-1637 OSGi support is broken in Log4j2 2.7
- Closed
-
LOG4J2-1660 ThreadContext to expose ReadOnlyThreadContextMap internal data structure
- Closed