Uploaded image for project: 'Log4j 2'
  1. Log4j 2
  2. LOG4J2-1876

Unreliable checking for runtime dependencies

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.8.2
    • Fix Version/s: 2.9.0
    • Component/s: Core
    • Labels:
      None

      Description

      If I include this in Maven POM:

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

      I get this printed on STDERR on startup:

      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
      

        Activity

        Hide
        mikaelstaldal Mikael Ståldal added a comment -

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

            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;
                }
            }
        

        What do you think.

        Show
        mikaelstaldal Mikael Ståldal added a comment - I think this can be fixed by changing LoaderUtil.isClassAvailable like this: 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 ; } } What do you think.
        Hide
        jvz Matt Sicker added a comment -

        That would be appropriate. Also, I don't think you meant to assign this to me?

        Show
        jvz Matt Sicker added a comment - That would be appropriate. Also, I don't think you meant to assign this to me?
        Hide
        jira-bot ASF subversion and git services added a comment -

        Commit b04e5a7eed22a9f1e66c1a378bec6c2d57cd1cbf in logging-log4j2's branch refs/heads/master from Mikael Ståldal
        [ https://git-wip-us.apache.org/repos/asf?p=logging-log4j2.git;h=b04e5a7 ]

        LOG4J2-1876 More reliable checking for runtime dependencies

        Show
        jira-bot ASF subversion and git services added a comment - Commit b04e5a7eed22a9f1e66c1a378bec6c2d57cd1cbf in logging-log4j2's branch refs/heads/master from Mikael Ståldal [ https://git-wip-us.apache.org/repos/asf?p=logging-log4j2.git;h=b04e5a7 ] LOG4J2-1876 More reliable checking for runtime dependencies
        Hide
        mikaelstaldal Mikael Ståldal added a comment -

        In Git master.

        Show
        mikaelstaldal Mikael Ståldal added a comment - In Git master.

          People

          • Assignee:
            mikaelstaldal Mikael Ståldal
            Reporter:
            mikaelstaldal Mikael Ståldal
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development