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

ThrowableProxy throws NoClassDefFoundError

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • None
    • 2.2
    • None
    • None

    Description

      In method loadClass we expect ClassNotFoundException. But if class comes from another java machine we can get NoClassDefFoundError.

      Possible fix:

      private Class<?> loadClass(final ClassLoader lastLoader, final String className) {
             // XXX: this is overly complicated
             Class<?> clazz;
             if (lastLoader != null) {
                 try {
                     clazz = Loader.initializeClass(className, lastLoader);
                     if (clazz != null) {
                         return clazz;
                     }
                 } catch (final Throwable ignore) {
                     // Ignore exception.
                 }
             }
             try {
                 clazz = Loader.loadClass(className);
             } catch (final ClassNotFoundException | LinkageError ignored) {
                 try {
                     clazz = Loader.initializeClass(className, this.getClass().getClassLoader());
                 } catch (final ClassNotFoundException | LinkageError ignore) {
                     return null;
                 }
             }
             return clazz;
         }
      

      Attachments

        1. 0001-LOG4J2-834-Ignores-NoClassDefFoundError-and-other-Th.patch
          5 kB
          Thiago Kronig
        2. ForceNoDefClassFoundError.java
          0.6 kB
          Thiago Kronig
        3. InexistentInterface.java
          0.1 kB
          Thiago Kronig

        Issue Links

          Activity

            People

              ggregory Gary D. Gregory
              ndkoval Nikita Koval
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: