in src/main/java/org/apache/commons/logging/impl/SimpleLog.java [619:666]
private static ClassLoader getContextClassLoader() {
ClassLoader classLoader = null;
try {
// Are we running on a JDK 1.2 or later system?
final Method method = Thread.class.getMethod("getContextClassLoader", (Class[]) null);
// Get the thread context class loader (if there is one)
try {
classLoader = (ClassLoader) method.invoke(Thread.currentThread(), (Class[]) null);
} catch (final IllegalAccessException e) {
// ignore
} catch (final InvocationTargetException e) {
/**
* InvocationTargetException is thrown by 'invoke' when
* the method being invoked (getContextClassLoader) throws
* an exception.
*
* getContextClassLoader() throws SecurityException when
* the context class loader isn't an ancestor of the
* calling class's class loader, or if security
* permissions are restricted.
*
* In the first case (not related), we want to ignore and
* keep going. We cannot help but also ignore the second
* with the logic below, but other calls elsewhere (to
* obtain a class loader) will trigger this exception where
* we can make a distinction.
*/
if (!(e.getTargetException() instanceof SecurityException)) {
// Capture 'e.getTargetException()' exception for details
// alternate: log 'e.getTargetException()', and pass back 'e'.
throw new LogConfigurationException
("Unexpected InvocationTargetException", e.getTargetException());
}
}
} catch (final NoSuchMethodException e) {
// Assume we are running on JDK 1.1
// ignore
}
if (classLoader == null) {
classLoader = SimpleLog.class.getClassLoader();
}
// Return the selected class loader
return classLoader;
}