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

Improper class bundling for an OSGi container's environment.

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Duplicate
    • Affects Version/s: 2.7
    • Fix Version/s: 2.8
    • Component/s: API, Core
    • Labels:
    • Environment:

      Eclipse Equinox OSGi container

      Description

      I use org.apache.logging.log4j:log4j-api:2.7 and org.apache.logging.log4j:log4j-core:2.7 from Maven Central Repository.

      During a OSGi container's startup I get the following exception:

      org.osgi.framework.BundleException: Exception in org.eclipse.gemini.web.tomcat.internal.Activator.start() of bundle org.eclipse.gemini.web.tomcat.
      at org.eclipse.osgi.internal.framework.BundleContextImpl.startActivator(BundleContextImpl.java:792)
      at org.eclipse.osgi.internal.framework.BundleContextImpl.start(BundleContextImpl.java:721)
      at org.eclipse.osgi.internal.framework.EquinoxBundle.startWorker0(EquinoxBundle.java:941)
      at org.eclipse.osgi.internal.framework.EquinoxBundle$EquinoxModule.startWorker(EquinoxBundle.java:318)
      at org.eclipse.osgi.container.Module.doStart(Module.java:571)
      at org.eclipse.osgi.container.Module.start(Module.java:439)
      at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.incStartLevel(ModuleContainer.java:1582)
      at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.incStartLevel(ModuleContainer.java:1562)
      at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.doContainerStartLevel(ModuleContainer.java:1533)
      at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.dispatchEvent(ModuleContainer.java:1476)
      at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.dispatchEvent(ModuleContainer.java:1)
      at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)
      at org.eclipse.osgi.framework.eventmgr.EventManager$EventThread.run(EventManager.java:340)
      Caused by: java.lang.NoClassDefFoundError: org/apache/logging/log4j/ThreadContextAccess
      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.osgi.BundleContextSelector.locateContext(BundleContextSelector.java:67)
      at org.apache.logging.log4j.core.osgi.BundleContextSelector.getContext(BundleContextSelector.java:53)
      at org.apache.logging.log4j.core.selector.ClassLoaderContextSelector.getContext(ClassLoaderContextSelector.java:57)
      at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:147)
      at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:45)
      at org.apache.logging.log4j.LogManager.getContext(LogManager.java:194)
      at org.apache.logging.log4j.spi.AbstractLoggerAdapter.getContext(AbstractLoggerAdapter.java:103)
      at org.apache.logging.slf4j.Log4jLoggerFactory.getContext(Log4jLoggerFactory.java:43)
      at org.apache.logging.log4j.spi.AbstractLoggerAdapter.getLogger(AbstractLoggerAdapter.java:42)
      at org.apache.logging.slf4j.Log4jLoggerFactory.getLogger(Log4jLoggerFactory.java:29)
      at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:358)
      at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:383)
      at org.eclipse.gemini.web.tomcat.internal.TomcatWebContainerProperties.<clinit>(TomcatWebContainerProperties.java:45)
      at org.eclipse.gemini.web.tomcat.internal.Activator.registerConnectorDescriptors(Activator.java:74)
      at org.eclipse.gemini.web.tomcat.internal.Activator.start(Activator.java:57)
      at org.eclipse.osgi.internal.framework.BundleContextImpl$3.run(BundleContextImpl.java:771)
      at org.eclipse.osgi.internal.framework.BundleContextImpl$3.run(BundleContextImpl.java:1)
      at java.security.AccessController.doPrivileged(Native Method)
      at org.eclipse.osgi.internal.framework.BundleContextImpl.startActivator(BundleContextImpl.java:764)
      ... 12 more
      Caused by: java.lang.ClassNotFoundException: org.apache.logging.log4j.ThreadContextAccess cannot be found by org.apache.logging.log4j.core_2.7.0
      at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:389)
      at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:352)
      at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:344)
      at org.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass(ModuleClassLoader.java:160)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
      ... 38 more
      I would like to share the result of my investigation:

      Analysis:
      The reason of this exception is quite clear - org.apache.logging.log4j.ThreadContextAccess cannot be found by org.apache.logging.log4j.core_2.7.0
      But, if you check the contents of log4j-core-2.7.jar you will see that class is present there. It seems strange for regular Java class-loading based on classpath. In an OSGi environment the class-loading rules a bit different, and further analysis showed the following:
      1. log4j-core bundle does not export org.apache.log4j package
      2. log4j-api bundle do export org.apache.log4j package
      3. log4j-api bundle is responsible for loading classes related to the org.apache.log4j package but it does not contain ThreadContextAccess class.

      Conclusion & Resolution:
      This issue does not affect regular Java environment. It is actual only for OSGi environments.
      I see several possible solutions:
      1. Move ThreadContextAccess class from log4j-core bundle into log4j-api bundle.
      2. Move into different package inside log4j-core in order to prevent package' name collisions with log4j-api.

      I have tested #1 solution and it fixes the problem.
      Hope you will fix this problem, as it actually a blocker issue for OSGi applications.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                rpopma Remko Popma
                Reporter:
                Harhserg Sergei Kharkhardin
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: