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

BasicContextSelector cannot be used in a OSGI application

VotersWatch issueWatchersLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.11.1
    • 3.0.0, 2.11.2
    • API, Core
    • None

    Description

      Using BasicContextSelector does not work when using Log4j in an OSGI application, see discussion on the mailing list: http://mail-archives.apache.org/mod_mbox/logging-log4j-user/201810.mbox/%3cAAA02DBF-18FF-4F31-9F5A-BAF4DBDBD679@dslextreme.com%3e

       

      Basically, the problem is that core-class BasicContextSelector is being loaded by LoaderUtil class that is living in log4j-api which cannot access classes in log4j-core.

      This is the error that occurs:

      ERROR StatusLogger Unable to create custom ContextSelector. Falling back to default.
       java.lang.ClassNotFoundException: org.apache.logging.log4j.core.selector.BasicContextSelector cannot be found by org.apache.logging.log4j.api_2.11.2.SNAPSHOT
      at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:508)
      at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:419)
      at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:411)
      at org.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass(ModuleClassLoader.java:150)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
      at java.lang.Class.forName0(Native Method)
      at java.lang.Class.forName(Class.java:264)
      at org.apache.logging.log4j.util.LoaderUtil.loadClass(LoaderUtil.java:168)
      at org.apache.logging.log4j.util.LoaderUtil.newInstanceOf(LoaderUtil.java:207)
      at org.apache.logging.log4j.util.LoaderUtil.newCheckedInstanceOf(LoaderUtil.java:228)
      at org.apache.logging.log4j.util.LoaderUtil.newCheckedInstanceOfProperty(LoaderUtil.java:253)
      at org.apache.logging.log4j.core.impl.Log4jContextFactory.createContextSelector(Log4jContextFactory.java:98)
      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:62)
      at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
      at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
      at java.lang.Class.newInstance(Class.java:442)
      at org.apache.logging.log4j.LogManager.<clinit>(LogManager.java:94)
      at org.apache.logging.log4j.spi.AbstractLoggerAdapter.getContext(AbstractLoggerAdapter.java:121)
      at org.apache.logging.slf4j.Log4jLoggerFactory.getContext(Log4jLoggerFactory.java:49)
      at org.apache.logging.log4j.spi.AbstractLoggerAdapter.getLogger(AbstractLoggerAdapter.java:46)
      at org.apache.logging.slf4j.Log4jLoggerFactory.getLogger(Log4jLoggerFactory.java:29)
      at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:355)
      at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:380)
      at com.servoy.j2db.server.main.Activator.<clinit>(Activator.java:44)
      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:423)
      at java.lang.Class.newInstance(Class.java:442)
      at org.eclipse.osgi.internal.framework.BundleContextImpl.loadBundleActivator(BundleContextImpl.java:763)
      at org.eclipse.osgi.internal.framework.BundleContextImpl.start(BundleContextImpl.java:716)
      at org.eclipse.osgi.internal.framework.EquinoxBundle.startWorker0(EquinoxBundle.java:1002)
      at org.eclipse.osgi.internal.framework.EquinoxBundle$EquinoxModule.startWorker(EquinoxBundle.java:354)
      at org.eclipse.osgi.container.Module.doStart(Module.java:581)
      at org.eclipse.osgi.container.Module.start(Module.java:449)
      at org.eclipse.osgi.framework.util.SecureAction.start(SecureAction.java:468)
      at org.eclipse.osgi.internal.hooks.EclipseLazyStarter.postFindLocalClass(EclipseLazyStarter.java:114)
      at org.eclipse.osgi.internal.loader.classpath.ClasspathManager.findLocalClass(ClasspathManager.java:505)
      at org.eclipse.osgi.internal.loader.ModuleClassLoader.findLocalClass(ModuleClassLoader.java:328)
      at org.eclipse.osgi.internal.loader.BundleLoader.findLocalClass(BundleLoader.java:392)
      at org.eclipse.osgi.internal.loader.sources.SingleSourcePackage.loadClass(SingleSourcePackage.java:36)
      at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:466)
      at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:419)
      at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:411)
      at org.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass(ModuleClassLoader.java:150)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:357)

       

      A fix for LOG4J2-920 was done with a similar issue in which a dependency from log4j-api to log4j-core was created in the manifest file.

       

      As discussed on the mailing list, I will file a pull request that allows BasicContextSelector to work in an OSGI setup and removes the unwanted dependency again.

      Attachments

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            Unassigned Unassigned
            rgansevles Rob Gansevles
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment