Skip to content

Commit d94ebec

Browse files
committed
fix guthub issue 715
Signed-off-by: Ceki Gulcu <[email protected]>
1 parent c76b303 commit d94ebec

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

Diff for: logback-classic/src/main/java/ch/qos/logback/classic/util/ContextInitializer.java

+6
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import ch.qos.logback.core.spi.ContextAwareImpl;
2222
import ch.qos.logback.core.status.InfoStatus;
2323
import ch.qos.logback.core.util.EnvUtil;
24+
import ch.qos.logback.core.util.Loader;
2425
import ch.qos.logback.core.util.StatusListenerConfigHelper;
2526

2627
import java.util.Comparator;
@@ -65,7 +66,12 @@ public void autoConfig() throws JoranException {
6566
autoConfig(Configurator.class.getClassLoader());
6667
}
6768

69+
6870
public void autoConfig(ClassLoader classLoader) throws JoranException {
71+
72+
// see https://github.com/qos-ch/logback/issues/715
73+
classLoader = Loader.systemClassloaderIfNull(classLoader);
74+
6975
String versionStr = EnvUtil.logbackVersion();
7076
if (versionStr == null) {
7177
versionStr = CoreConstants.NA;

Diff for: logback-core/src/main/java/ch/qos/logback/core/util/Loader.java

+15-1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,21 @@ public Boolean run() {
5656
});
5757
}
5858

59+
/**
60+
* This method is used to sanitize the <code>cl</code> argument in case it is null.
61+
*
62+
* @param cl a class loader, may be null
63+
* @return the system class loader if the <code>cl</code> argument is null, return <code>cl</code> otherwise.
64+
*
65+
* @since 1.4.12
66+
*/
67+
public static ClassLoader systemClassloaderIfNull(ClassLoader cl) {
68+
if(cl == null)
69+
return ClassLoader.getSystemClassLoader();
70+
else
71+
return cl;
72+
}
73+
5974
/**
6075
* Compute the number of occurrences a resource can be found by a class loader.
6176
*
@@ -64,7 +79,6 @@ public Boolean run() {
6479
* @return
6580
* @throws IOException
6681
*/
67-
6882
public static Set<URL> getResources(String resource, ClassLoader classLoader) throws IOException {
6983
// See LBCLASSIC-159
7084
Set<URL> urlSet = new HashSet<URL>();

0 commit comments

Comments
 (0)