Skip to content

Commit

Permalink
fix guthub issue 715
Browse files Browse the repository at this point in the history
Signed-off-by: Ceki Gulcu <[email protected]>
  • Loading branch information
ceki committed Nov 6, 2023
1 parent 7ae0a7b commit bf59a63
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
16 changes: 15 additions & 1 deletion logback-core/src/main/java/ch/qos/logback/core/util/Loader.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,21 @@ public Boolean run() {
});
}

/**
* This method is used to sanitize the <code>cl</code> argument in case it is null.
*
* @param cl a class loader, may be null
* @return the system class loader if the <code>cl</code> argument is null, return <code>cl</code> 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.
*
Expand All @@ -64,7 +79,6 @@ public Boolean run() {
* @return
* @throws IOException
*/

public static Set<URL> getResources(String resource, ClassLoader classLoader) throws IOException {
// See LBCLASSIC-159
Set<URL> urlSet = new HashSet<URL>();
Expand Down

0 comments on commit bf59a63

Please sign in to comment.