private ClassLoader getBaseClassLoader()

in src/main/java/org/apache/commons/logging/impl/LogFactoryImpl.java [679:735]


    private ClassLoader getBaseClassLoader() throws LogConfigurationException {
        final ClassLoader thisClassLoader = getClassLoader(LogFactoryImpl.class);

        if (!useTCCL) {
            return thisClassLoader;
        }

        final ClassLoader contextClassLoader = getContextClassLoaderInternal();

        final ClassLoader baseClassLoader = getLowestClassLoader(
                contextClassLoader, thisClassLoader);

        if (baseClassLoader == null) {
           // The two class loaders are not part of a parent child relationship.
           // In some classloading setups (e.g. JBoss with its
           // UnifiedLoaderRepository) this can still work, so if user hasn't
           // forbidden it, just return the contextClassLoader.
           if (!allowFlawedContext) {
            throw new LogConfigurationException("Bad class loader hierarchy; LogFactoryImpl was loaded via" +
                                                " a class loader that is not related to the current context" +
                                                " class loader.");
           }
        if (isDiagnosticsEnabled()) {
               logDiagnostic("[WARNING] the context class loader is not part of a" +
                             " parent-child relationship with the class loader that" +
                             " loaded LogFactoryImpl.");
          }
          // If contextClassLoader were null, getLowestClassLoader() would
          // have returned thisClassLoader.  The fact we are here means
          // contextClassLoader is not null, so we can just return it.
          return contextClassLoader;
        }

        if (baseClassLoader != contextClassLoader) {
            // We really should just use the contextClassLoader as the starting
            // point for scanning for log adapter classes. However it is expected
            // that there are a number of broken systems out there which create
            // custom class loaders but fail to set the context class loader so
            // we handle those flawed systems anyway.
            if (!allowFlawedContext) {
                throw new LogConfigurationException(
                        "Bad class loader hierarchy; LogFactoryImpl was loaded via" +
                        " a class loader that is not related to the current context" +
                        " class loader.");
            }
            if (isDiagnosticsEnabled()) {
                logDiagnostic(
                        "Warning: the context class loader is an ancestor of the" +
                        " class loader that loaded LogFactoryImpl; it should be" +
                        " the same or a descendant. The application using" +
                        " commons-logging should ensure the context class loader" +
                        " is used correctly.");
            }
        }

        return baseClassLoader;
    }