logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Remko Popma (JIRA)" <j...@apache.org>
Subject [jira] [Comment Edited] (LOG4J2-477) NPE in ClassLoaderContextSelector
Date Tue, 24 Dec 2013 10:44:51 GMT

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

Remko Popma edited comment on LOG4J2-477 at 12/24/13 10:44 AM:
---------------------------------------------------------------

Tal, thanks for checking!
I've made the following change:

{code}
private LoggerContext locateContext(final ClassLoader loaderOrNull, final URI configLocation)
{
    final ClassLoader loader = loaderOrNull != null ? loaderOrNull : ClassLoader.getSystemClassLoader();
    final String name = loader.toString();
...
        CONTEXT_MAP.putIfAbsent(name, r);
        ctx = CONTEXT_MAP.get(name).get().get();
...
{code}

This preserves the semantics of the original code: it ensure that the CONTEXT_MAP _always_
has a value for the classloader name.

The only assumption I'm making when fixing this bug is that if {{null}} is passed in as the
classLoader, then the system class loader is an appropriate replacement. To be honest I am
not 100% sure this is correct, but I figured it is better than a NullPointerException...

Fixed in revision 1553262.
Please verify and close.


was (Author: remkop@yahoo.com):
Tal, thanks for checking!
I've made the following change:

{code}
private LoggerContext locateContext(final ClassLoader loaderOrNull, final URI configLocation)
{
    final ClassLoader loader = loaderOrNull != null ? loaderOrNull : ClassLoader.getSystemClassLoader();
    final String name = loader.toString();
...
        CONTEXT_MAP.putIfAbsent(name, r);
        ctx = CONTEXT_MAP.get(name).get().get();
...
{code}

This preserves the semantics of the original code: it ensure that the CONTEXT_MAP _always_
has a value for the classloader name.

The only assumption I'm making when fixing this bug is that if {{null}} is passed in as the
classLoader, then the system class loader is an appropriate replacement. To be honest I am
not 100% sure this is correct, but I figured it is better than a NullPointerException...

> NPE in ClassLoaderContextSelector
> ---------------------------------
>
>                 Key: LOG4J2-477
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-477
>             Project: Log4j 2
>          Issue Type: Improvement
>          Components: Core
>    Affects Versions: 2.0-beta9
>            Reporter: Tal Liron
>            Assignee: Remko Popma
>
> The problem is that some classes don't have class loaders: this can happen when working
with dynamic JVM languages (Rhino, Jython, etc.)
> Here's the stack trace I got:
> {code}
> java.lang.NullPointerException
> 	at org.apache.logging.log4j.core.selector.ClassLoaderContextSelector.locateContext(ClassLoaderContextSelector.java:182)
> 	at org.apache.logging.log4j.core.selector.ClassLoaderContextSelector.getContext(ClassLoaderContextSelector.java:145)
> 	at org.apache.logging.log4j.core.selector.ClassLoaderContextSelector.getContext(ClassLoaderContextSelector.java:81)
> 	at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:83)
> 	at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:34)
> {code}



--
This message was sent by Atlassian JIRA
(v6.1.5#6160)

---------------------------------------------------------------------
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