diff --git a/logback-classic/src/main/java/ch/qos/logback/classic/util/ContextInitializer.java b/logback-classic/src/main/java/ch/qos/logback/classic/util/ContextInitializer.java index 086b457002..32132d23a3 100644 --- a/logback-classic/src/main/java/ch/qos/logback/classic/util/ContextInitializer.java +++ b/logback-classic/src/main/java/ch/qos/logback/classic/util/ContextInitializer.java @@ -100,6 +100,10 @@ public void autoConfig(ClassLoader classLoader) throws JoranException { } private Configurator instantiateConfiguratorByClassName(String configuratorClassName, ClassLoader classLoader) { + if (classLoader == null) { + contextAware.addInfo("Instantiation failure: null ClassLoader"); + return null; + } try { Class classObj = classLoader.loadClass(configuratorClassName); return (Configurator) classObj.getConstructor().newInstance(); diff --git a/logback-classic/src/test/java/ch/qos/logback/classic/util/ContextInitializerTest.java b/logback-classic/src/test/java/ch/qos/logback/classic/util/ContextInitializerTest.java index 28687eb0b7..af2f6c467e 100755 --- a/logback-classic/src/test/java/ch/qos/logback/classic/util/ContextInitializerTest.java +++ b/logback-classic/src/test/java/ch/qos/logback/classic/util/ContextInitializerTest.java @@ -122,6 +122,13 @@ public void autoConfigFromServiceLoaderJDK6andAbove() throws Exception { assertSame(loggerContext, MockConfigurator.context); } + @Test + public void autoConfigFromBootstrapClassLoader() throws Exception { + assertNull(MockConfigurator.context); + new ContextInitializer(loggerContext).autoConfig(null); + assertNull(MockConfigurator.context); + } + @Test public void autoConfigFromServiceLoaderJDK5() throws Exception { assumeTrue(isJDK5());