private static ClassLoader getContextClassLoader()

in src/main/java/org/apache/commons/logging/impl/SimpleLog.java [170:197]


    private static ClassLoader getContextClassLoader() {
        ClassLoader classLoader = null;

        // Get the thread context class loader (if there is one)
        try {
            classLoader = Thread.currentThread().getContextClassLoader();
        } catch (final RuntimeException e) {
            /**
             * 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.
             */
            // Capture 'e.getTargetException()' exception for details
            // alternate: log 'e.getTargetException()', and pass back 'e'.
            if (!(e instanceof SecurityException)) {
                throw new LogConfigurationException("Unexpected SecurityException", e);
            }
        }

        if (classLoader == null) {
            classLoader = SimpleLog.class.getClassLoader();
        }

        // Return the selected class loader
        return classLoader;
    }