logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Tim Tucker (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (LOG4J2-248) Log4jContextListener: Use Thread instead of Class for fallback classloader
Date Thu, 09 May 2013 23:54:13 GMT

    [ https://issues.apache.org/jira/browse/LOG4J2-248?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13653392#comment-13653392
] 

Tim Tucker commented on LOG4J2-248:
-----------------------------------

It looks like more recent versions of Struts actually have the logic separated out into its
own class, loading in the following order of preference:
1.    From Thread.currentThread().getContextClassLoader()
2.    From ClassLoaderUtil.class.getClassLoader()
3.    From the callingClass.getClassLoader() 

http://struts.apache.org/release/2.3.x/xwork-core/apidocs/com/opensymphony/xwork2/util/ClassLoaderUtil.html
                
> Log4jContextListener: Use Thread instead of Class for fallback classloader
> --------------------------------------------------------------------------
>
>                 Key: LOG4J2-248
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-248
>             Project: Log4j 2
>          Issue Type: Improvement
>    Affects Versions: 2.0-beta5
>            Reporter: Tim Tucker
>            Priority: Minor
>
> 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();
> }

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org


Mime
View raw message