Markus Jung created TOMEE-4390:
----------------------------------

             Summary: ClassNotFoundException in webapp that has log4j2 and 
invokes commons-logging
                 Key: TOMEE-4390
                 URL: https://issues.apache.org/jira/browse/TOMEE-4390
             Project: TomEE
          Issue Type: Bug
          Components: TomEE Core Server
    Affects Versions: 10.0.0-M2
            Reporter: Markus Jung
         Attachments: log4j2-commons-logging.zip

Accessing commons-logging throws an exception when it is being invoked in an 
application that has a log4j2 dependency but no commons-logging dependency

The layout is basically:
 * tomee
 ** libs/
 *** commons-logging.jar
 ** webapps/ROOT/WEB-INF/libs
 *** log4j2-api/core.jar

 

This causes the following to happen:
 # commons-logging checks the current thread classloader for a log4j2 class
 # if it finds one, it creates an instance of Log4jApiLogFactory
 # while doing so, java tries to load the class 
org.apache.logging.log4j.spi.LoggerAdapter using the classloader that loaded 
commons-logging.jar
 # ClassNotFoundException with a very incomprehensible stacktrace

 

See attached reproducer, simply run mvn package tomee:run

 

Stacktrace:
{code:java}
        Caused by: java.lang.NoClassDefFoundError: 
org/apache/logging/log4j/spi/LoggerAdapter
                at java.base/java.lang.Class.forName0(Native Method)
                at java.base/java.lang.Class.forName(Class.java:375)
                at 
org.apache.commons.logging.LogFactory.createFactory(LogFactory.java:419)
                at 
org.apache.commons.logging.LogFactory.lambda$newFactory$3(LogFactory.java:1431)
                at 
java.base/java.security.AccessController.doPrivileged(AccessController.java:318)
                at 
org.apache.commons.logging.LogFactory.newFactory(LogFactory.java:1431)
                at 
org.apache.commons.logging.LogFactory.getFactory(LogFactory.java:928)
                at 
org.apache.commons.logging.LogFactory.getLog(LogFactory.java:987)
                at com.example.ExampleBean.initApplication(ExampleBean.java:15)
                at 
java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                at 
java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
                at 
java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
                at java.base/java.lang.reflect.Method.invoke(Method.java:569)
                at 
org.apache.webbeans.event.ObserverMethodImpl.invoke(ObserverMethodImpl.java:410)
                at 
org.apache.webbeans.event.ObserverMethodImpl.notify(ObserverMethodImpl.java:371)
                ... 49 more
        Caused by: java.lang.ClassNotFoundException: 
org.apache.logging.log4j.spi.LoggerAdapter
                at 
java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:445)
                at 
java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:592)
                at 
java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:525)
                ... 64 more

{code}
 



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to