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

Log4jWebInitializerImpl: Use Thread instead of Class for fallback classloader

    Details

    • Type: Improvement
    • Status: Resolved
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 2.0-beta5
    • Fix Version/s: 2.6
    • Component/s: None
    • Labels:
      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

              • Assignee:
                jvz Matt Sicker
                Reporter:
                timtucker Tim Tucker
              • Votes:
                0 Vote for this issue
                Watchers:
                5 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: