Details
-
Improvement
-
Status: Resolved
-
Minor
-
Resolution: Fixed
-
2.0-beta5
-
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
- breaks
-
LOG4J2-1841 Problems with consequences after LOG4J2-248
- Closed