[ https://issues.apache.org/jira/browse/LOG4J2-1971?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16081177#comment-16081177 ]
Gary Gregory edited comment on LOG4J2-1971 at 7/10/17 9:25 PM: --------------------------------------------------------------- Hello, I refactored the code to make the check on both cases. Please test the latest 2.9-SNAPSHOT jars from the Apache Snapshot Maven repository: https://repository.apache.org/content/repositories/snapshots/ Please update this issue with your findings. Thank you, Gary was (Author: garydgregory): I refactored the code to make the check on both cases. Please test the latest 2.9-SNAPSHOT jars from the Apache Snapshot Maven repository: https://repository.apache.org/content/repositories/snapshots/ > ClassCastException: org.eclipse.osgi.internal.loader.SystemBundleLoader$1 > cannot be cast to java.lang.ClassLoader > ----------------------------------------------------------------------------------------------------------------- > > Key: LOG4J2-1971 > URL: https://issues.apache.org/jira/browse/LOG4J2-1971 > Project: Log4j 2 > Issue Type: Bug > Affects Versions: 2.8 > Reporter: liwenxian2017 > Fix For: 2.9 > > > 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. -- This message was sent by Atlassian JIRA (v6.4.14#64029)