[ 
https://issues.apache.org/jira/browse/LOG4J2-1971?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16084371#comment-16084371
 ] 

Gary Gregory commented on LOG4J2-1971:
--------------------------------------

The class {{org.apache.logging.log4j.core.impl.Log4jProvider}} has been around 
for a while, it is not new in 2.9-SNAPSHOTs.

This error seems to say that 
{{org.apache.logging.log4j.core.impl.Log4jProvider}} is not a subtype of 
{{org.apache.logging.log4j.spi.Provider}}, which it is in our code:

{code:java}
/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements. See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache license, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the license for the specific language governing permissions and
 * limitations under the license.
 */
package org.apache.logging.log4j.core.impl;

import org.apache.logging.log4j.spi.Provider;

/**
 * Binding for the Log4j API.
 */
public class Log4jProvider extends Provider {
    public Log4jProvider() {
        super(10, "2.6.0", Log4jContextFactory.class);
    }
}
{code}

This smells like something is not as we expect with class loaders in OSGi, but 
what?

> 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)

Reply via email to