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

Performance issue with stack traces containing generated classes

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: 2.12.1
    • Fix Version/s: None
    • Component/s: Core
    • Labels:
      None

      Description

      We've noticed a performance problem with stack traces that contain certain types of generated classes. For example:

      16 Aug 2019 15:54:33,470 [INFO]  (main) com.example.LoggingIntegrationTest: Exception thrown
      java.lang.reflect.InvocationTargetException: null
      	at jdk.internal.reflect.GeneratedConstructorAccessor10.newInstance(Unknown Source) ~[?:?]
      	at jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[?:?]
      	at java.lang.reflect.Constructor.newInstance(Constructor.java:490) ~[?:?]
      	at com.example.LoggingIntegrationTest.construct(LoggingIntegrationTest.java:25) ~[classes/:?]
      

      In this example, jdk.internal.reflect.GeneratedConstructorAccessor10 is a class generated by the JDK in order to optimize the reflective Constructor#newInstance call. One quirk of these classes (called "inflated constructors" within the JDK) is that they get loaded in their very own classloader. Since Log4j2 has no hope of finding this classloader, it also cannot resolve the class name to a Class object in ThrowableProxyHelper#loadClass. This means that every stack trace containing such a class, when it is rendered, will cause the entire classpath to be scanned.

      It seems that ThrowableProxyHelper should have some sort of negative caching in order to optimize this case.

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              rschmitt Ryan Schmitt
            • Votes:
              1 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated: