[
https://issues.apache.org/jira/browse/LOG4J2-1658?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15631997#comment-15631997
]
Remko Popma commented on LOG4J2-1658:
-------------------------------------
Looking at this again, I am not sure that modifying {{ContextMapLookup}} is the
best way to fix this. The underlying problem is that there are code paths where
the LogManager's LoggerContextFactory field is being accessed before
initialization of this LoggerContextFactory is complete.
It seems more robust to modify
{{ThreadContextMapFactory::createThreadContextMap}} so that it can handle the
case where LogManager::getFactory returns null.
The simplest fix would be to skip the ProviderUtil-based logic in
ThreadContextMapFactory::createThreadContextMap completely when the factory is
null. [~ralphgoers], please let me know if you want to handle this differently.
> 2.7 - ThreadContextAccess.getThreadContextMap NPE when specifying
> BasicContextSelector
> --------------------------------------------------------------------------------------
>
> Key: LOG4J2-1658
> URL: https://issues.apache.org/jira/browse/LOG4J2-1658
> Project: Log4j 2
> Issue Type: Bug
> Components: Core
> Affects Versions: 2.7
> Environment: Windows, JVM 1.8.0_66
> Reporter: Leon Finker
> Assignee: Remko Popma
>
> 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.
> {noformat}
> 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
> {noformat}
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]