Uploaded image for project: 'Log4j 2'
  1. Log4j 2
  2. LOG4J2-1658

2.7 - ThreadContextAccess.getThreadContextMap NPE when specifying BasicContextSelector

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.7
    • Fix Version/s: 2.8
    • Component/s: Core
    • Labels:
      None
    • Environment:

      Windows, JVM 1.8.0_66

      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

            Activity

              People

              • Assignee:
                remkop@yahoo.com Remko Popma
                Reporter:
                leonfin Leon Finker
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: