[ https://issues.apache.org/jira/browse/LOG4J2-1971?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16085142#comment-16085142 ]
Ralph Goers edited comment on LOG4J2-1971 at 7/13/17 4:17 AM: -------------------------------------------------------------- So the difference between 2.8.2 and 2.9 is that in 2.9 ServiceLoader loads the Provider - and that class is in the target bundle. In 2.8.2 we read the data from a file in the target bundle and the Provider was created in the API bundle, which is why we didn't get the ClassNotFound exception. But something doesn't seem right about this. We are using the ServiceLoader.load method that accepts a ClassLoader, with the OSGi doc says doesn't have the same problems as the version that doesn't.. But somehow that ClassLoader doesn't seem to have access to the log4j-api. was (Author: ralph.go...@dslextreme.com): So the difference between 2.8.2 and 2.9 is that in 2.9 ServiceLoader loads the Provider - and that class is in the target bundle. In 2.8.2 we read the data from a file in the target bundle and the Provider was created in the API bundle, which is why we didn't get the ClassNotFound exception. I guess I still have more work to do on this. > 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)