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..312a10e49d 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
@@ -21,6 +21,7 @@
import ch.qos.logback.core.spi.ContextAwareImpl;
import ch.qos.logback.core.status.InfoStatus;
import ch.qos.logback.core.util.EnvUtil;
+import ch.qos.logback.core.util.Loader;
import ch.qos.logback.core.util.StatusListenerConfigHelper;
import java.util.Comparator;
@@ -65,7 +66,12 @@ public void autoConfig() throws JoranException {
autoConfig(Configurator.class.getClassLoader());
}
+
public void autoConfig(ClassLoader classLoader) throws JoranException {
+
+ // see https://github.com/qos-ch/logback/issues/715
+ classLoader = Loader.systemClassloaderIfNull(classLoader);
+
String versionStr = EnvUtil.logbackVersion();
if (versionStr == null) {
versionStr = CoreConstants.NA;
diff --git a/logback-core/src/main/java/ch/qos/logback/core/util/Loader.java b/logback-core/src/main/java/ch/qos/logback/core/util/Loader.java
index 88ab0336d1..4959e6de6c 100644
--- a/logback-core/src/main/java/ch/qos/logback/core/util/Loader.java
+++ b/logback-core/src/main/java/ch/qos/logback/core/util/Loader.java
@@ -56,6 +56,21 @@ public Boolean run() {
});
}
+ /**
+ * This method is used to sanitize the cl
argument in case it is null.
+ *
+ * @param cl a class loader, may be null
+ * @return the system class loader if the cl
argument is null, return cl
otherwise.
+ *
+ * @since 1.4.12
+ */
+ public static ClassLoader systemClassloaderIfNull(ClassLoader cl) {
+ if(cl == null)
+ return ClassLoader.getSystemClassLoader();
+ else
+ return cl;
+ }
+
/**
* Compute the number of occurrences a resource can be found by a class loader.
*
@@ -64,7 +79,6 @@ public Boolean run() {
* @return
* @throws IOException
*/
-
public static Set getResources(String resource, ClassLoader classLoader) throws IOException {
// See LBCLASSIC-159
Set urlSet = new HashSet();