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

ClassCastException: org.eclipse.osgi.internal.loader.SystemBundleLoader$1 cannot be cast to java.lang.ClassLoader

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 2.8
    • 2.9.0
    • None
    • None

    Description

      When I migrated log4j from log4j 1.2.17 to log4j 2.8, There is an Exception like this:

      java.lang.ClassCastException: org.eclipse.osgi.internal.loader.SystemBundleLoader$1 cannot be cast to java.lang.ClassLoaderat org.eclipse.osgi.internal.resolver.BundleDescriptionImpl$DescriptionWiring.getClassLoader(BundleDescriptionImpl.java:1229) ~[org.eclipse.osgi.jar:?]at org.apache.logging.log4j.core.osgi.Activator.scanBundleForPlugins(Activator.java:70) ~[log4j-core.jar:2.8]at org.apache.logging.log4j.core.osgi.Activator.bundleChanged(Activator.java:91) ~[log4j-core.jar:2.8]at org.eclipse.osgi.framework.internal.core.BundleContextImpl.dispatchEvent(BundleContextImpl.java:847) ~[org.eclipse.osgi.jar:?]at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230) ~[org.eclipse.osgi.jar:?]at org.eclipse.osgi.framework.eventmgr.ListenerQueue.dispatchEventSynchronous(ListenerQueue.java:148) ~[org.eclipse.osgi.jar:?]at org.eclipse.osgi.framework.internal.core.Framework.publishBundleEventPrivileged(Framework.java:1568) ~[org.eclipse.osgi.jar:?]at org.eclipse.osgi.framework.internal.core.Framework.publishBundleEvent(Framework.java:1504) ~[org.eclipse.osgi.jar:?]at org.eclipse.osgi.framework.internal.core.Framework.publishBundleEvent(Framework.java:1499) ~[org.eclipse.osgi.jar:?]at org.eclipse.osgi.framework.internal.core.StartLevelManager.doSetStartLevel(StartLevelManager.java:247) ~[org.eclipse.osgi.jar:?]at org.eclipse.osgi.framework.internal.core.StartLevelManager.dispatchEvent(StartLevelManager.java:438) ~[org.eclipse.osgi.jar:?]at org.eclipse.osgi.framework.internal.core.StartLevelManager.dispatchEvent(StartLevelManager.java:1) ~[org.eclipse.osgi.jar:?]at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230) ~[org.eclipse.osgi.jar:?]at org.eclipse.osgi.framework.eventmgr.EventManager$EventThread.run(EventManager.java:340) ~[org.eclipse.osgi.jar:?]

      I checked Activator.java in log4j-core:

      ...
      86 @Override
      87 public void bundleChanged(final BundleEvent event) {
      88  switch (event.getType()) {
      89   // FIXME: STARTING instead of STARTED?
      90   case BundleEvent.STARTED:
      91    scanBundleForPlugins(event.getBundle());
      92   break;

      in line 91, it called scanBundleForPlugins for every bundles. But in line 60-61, it does not scan system bundle for plugins

      57 private static void scanInstalledBundlesForPlugins(final BundleContext context) {
      58  final Bundle[] bundles = context.getBundles();
      59   for (final Bundle bundle : bundles) {
      60    // LOG4J2-920: don't scan system bundle for plugins
      61    if (bundle.getState() == Bundle.ACTIVE && bundle.getBundleId() != 0) {
      62     // TODO: bundle state can change during this
      63     scanBundleForPlugins(bundle);

      And org.eclipse.osgi_3.8.1 's bundle ID is just 0. So it skipped bundle org.eclipse.osgi in line 61-63. but it does not in line 91

      If I changed line 91 to:
      if (event.getBundle().getState() == Bundle.ACTIVE && event.getBundle().getBundleId() != 0) 

      { scanBundleForPlugins(event.getBundle()); }

      The exception goes away.
      So is this a bug? Or this is NOT a bug and there is a workaround for this Exception? Thanks.

      Attachments

        Activity

          People

            Unassigned Unassigned
            liwenxian2017 liwenxian2017
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: