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

Log4jWebInitializerImpl: Use Thread instead of Class for fallback classloader

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • 2.0-beta5
    • 2.6
    • None
    • None

    Description

      I was experimenting with creating my own context listener based on Log4jContextListener and noticed that the call in getClassLoader to get the class's classloader was triggering a PMD warning.

      The rule's notes indicate that Thread.currentThread().getContextClassLoader() might return more reliable results than Object.class.getClassLoader().

      The code in question is as follows:
      try {
      // if container is Servlet 3.0, use its getClassLoader method
      return (ClassLoader)context.getClass().getMethod("getClassLoader").invoke(context);
      } catch (Exception ignore) {
      // otherwise, use this class's class loader
      return Log4jContextListener.class.getClassLoader();
      }

      Attachments

        Issue Links

          Activity

            People

              mattsicker Matt Sicker
              timtucker Tim Tucker
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: