logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mikael Ståldal (JIRA) <j...@apache.org>
Subject [jira] [Commented] (LOG4J2-1876) Unreliable checking for runtime dependencies
Date Tue, 11 Apr 2017 12:32:41 GMT

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

Mikael Ståldal commented on LOG4J2-1876:
----------------------------------------

I think this can be fixed by changing LoaderUtil.isClassAvailable like this:

{code}
    public static boolean isClassAvailable(final String className) {
        try {
            final Class<?> clazz = loadClass(className);
            return clazz != null;
        } catch (final ClassNotFoundException | LinkageError e) {
            return false;
        } catch (final Throwable e) {
            LowLevelLogUtil.logException("Unknown error checking for existence of class: "
+ className, e);
            return false;
        }
    }
{code}

What do you think.

> Unreliable checking for runtime dependencies
> --------------------------------------------
>
>                 Key: LOG4J2-1876
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-1876
>             Project: Log4j 2
>          Issue Type: Bug
>          Components: Core
>    Affects Versions: 2.8.2
>            Reporter: Mikael Ståldal
>            Assignee: Mikael Ståldal
>
> If I include this in Maven POM:
> {code}
> <dependency>
>     <groupId>com.fasterxml.jackson.core</groupId>
>     <artifactId>jackson-databind</artifactId>
>     <version>2.8.7</version>
>     <scope>runtime</scope>
>     <exclusions>
>         <exclusion>
>             <groupId>com.fasterxml.jackson.core</groupId>
>             <artifactId>jackson-core</artifactId>
>         </exclusion>
>     </exclusions>
> </dependency>
> {code}
> I get this printed on STDERR on startup:
> {code}
> Unknown error checking for existence of class: com.fasterxml.jackson.databind.ObjectMapper
> java.lang.NoClassDefFoundError: com/fasterxml/jackson/core/Versioned
> 	at java.lang.ClassLoader.defineClass1(Native Method)
> 	at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
> 	at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
> 	at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
> 	at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
> 	at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
> 	at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
> 	at java.security.AccessController.doPrivileged(Native Method)
> 	at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
> 	at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
> 	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
> 	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
> 	at java.lang.Class.forName0(Native Method)
> 	at java.lang.Class.forName(Class.java:264)
> 	at org.apache.logging.log4j.util.LoaderUtil.loadClass(LoaderUtil.java:141)
> 	at org.apache.logging.log4j.util.LoaderUtil.isClassAvailable(LoaderUtil.java:115)
> 	at org.apache.logging.log4j.core.util.Loader.isClassAvailable(Loader.java:310)
> 	at org.apache.logging.log4j.core.config.yaml.YamlConfigurationFactory.<init>(YamlConfigurationFactory.java:47)
> 	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
> 	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
> 	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
> 	at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
> 	at org.apache.logging.log4j.core.util.ReflectionUtil.instantiate(ReflectionUtil.java:188)
> 	at org.apache.logging.log4j.core.config.ConfigurationFactory.addFactory(ConfigurationFactory.java:190)
> 	at org.apache.logging.log4j.core.config.ConfigurationFactory.getInstance(ConfigurationFactory.java:164)
> 	at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:613)
> 	at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:634)
> 	at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:229)
> 	at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:242)
> 	at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:45)
> 	at org.apache.logging.log4j.LogManager.getContext(LogManager.java:174)
> 	at org.apache.logging.log4j.LogManager.getLogger(LogManager.java:618)
> 	at logtest.Main.<clinit>(Main.java:14)
> Caused by: java.lang.ClassNotFoundException: com.fasterxml.jackson.core.Versioned
> 	at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
> 	at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
> 	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
> 	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
> 	... 33 more
> Unknown error checking for existence of class: com.fasterxml.jackson.databind.ObjectMapper
> java.lang.NoClassDefFoundError: com/fasterxml/jackson/core/Versioned
> 	at java.lang.ClassLoader.defineClass1(Native Method)
> 	at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
> 	at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
> 	at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
> 	at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
> 	at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
> 	at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
> 	at java.security.AccessController.doPrivileged(Native Method)
> 	at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
> 	at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
> 	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
> 	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
> 	at java.lang.Class.forName0(Native Method)
> 	at java.lang.Class.forName(Class.java:264)
> 	at org.apache.logging.log4j.util.LoaderUtil.loadClass(LoaderUtil.java:141)
> 	at org.apache.logging.log4j.util.LoaderUtil.isClassAvailable(LoaderUtil.java:115)
> 	at org.apache.logging.log4j.core.util.Loader.isClassAvailable(Loader.java:310)
> 	at org.apache.logging.log4j.core.config.json.JsonConfigurationFactory.<init>(JsonConfigurationFactory.java:49)
> 	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
> 	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
> 	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
> 	at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
> 	at org.apache.logging.log4j.core.util.ReflectionUtil.instantiate(ReflectionUtil.java:188)
> 	at org.apache.logging.log4j.core.config.ConfigurationFactory.addFactory(ConfigurationFactory.java:190)
> 	at org.apache.logging.log4j.core.config.ConfigurationFactory.getInstance(ConfigurationFactory.java:164)
> 	at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:613)
> 	at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:634)
> 	at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:229)
> 	at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:242)
> 	at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:45)
> 	at org.apache.logging.log4j.LogManager.getContext(LogManager.java:174)
> 	at org.apache.logging.log4j.LogManager.getLogger(LogManager.java:618)
> 	at logtest.Main.<clinit>(Main.java:14)
> Caused by: java.lang.ClassNotFoundException: com.fasterxml.jackson.core.Versioned
> 	at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
> 	at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
> 	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
> 	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
> 	... 33 more
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org


Mime
View raw message