Skip to content

ClassLoaderContextSelector should create a separate context per classloader #2314

Open
@ppkarwasz

Description

@ppkarwasz

The ClassLoaderContextSelector#locateContext currently implements the following logic:

if (ref == null) {
if (configLocation == null) {
ClassLoader parent = loader.getParent();
while (parent != null) {
ref = CONTEXT_MAP.get(toContextMapKey(parent));
if (ref != null) {
final WeakReference<LoggerContext> r = ref.get();
final LoggerContext ctx = r.get();
if (ctx != null) {
return ctx;
}
}
parent = parent.getParent();
/* In Tomcat 6 the parent of the JSP classloader is the webapp classloader which would be
configured by the WebAppContextListener. The WebAppClassLoader is also the ThreadContextClassLoader.
In JBoss 5 the parent of the JSP ClassLoader is the WebAppClassLoader which is also the
ThreadContextClassLoader. However, the parent of the WebAppClassLoader is the ClassLoader
that is configured by the WebAppContextListener.
ClassLoader threadLoader = null;
try {
threadLoader = Thread.currentThread().getContextClassLoader();
} catch (Exception ex) {
// Ignore SecurityException
}
if (threadLoader != null && threadLoader == parent) {
break;
} else {
parent = parent.getParent();
} */
}
}

If the initial ContextSelector#getContext call does not provide a configLocation parameter and there is already a logger context associated to an ancestor of the loader classloader, no new context is created and the logger context of the ancestor is returned.

While this might be a feature to minimize the number of logger contexts, IMHO it should be optional and the default behavior should be to create a different logger context per classloader.

This behavior causes #1430 and the problems in #2311.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIncorrect, unexpected, or unintended behavior of existing code

    Type

    No type

    Projects

    Status

    To triage

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions