Commit 1ef77d7d authored by Phillip Webb's avatar Phillip Webb

Protect against null CodeSource location

Update LogbackLoggingSystem to protect against a potential null
CodeSource result.

Fixes gh-2149
parent c22018aa
......@@ -17,6 +17,8 @@
package org.springframework.boot.logging.logback;
import java.net.URL;
import java.security.CodeSource;
import java.security.ProtectionDomain;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
......@@ -107,8 +109,7 @@ public class LogbackLoggingSystem extends AbstractLoggingSystem {
"LoggerFactory is not a Logback LoggerContext but Logback is on "
+ "the classpath. Either remove Logback or the competing "
+ "implementation (%s loaded from %s).",
factory.getClass(), factory.getClass().getProtectionDomain()
.getCodeSource().getLocation()));
factory.getClass(), getLocation(factory)));
LoggerContext context = (LoggerContext) factory;
context.stop();
......@@ -123,6 +124,20 @@ public class LogbackLoggingSystem extends AbstractLoggingSystem {
}
}
private Object getLocation(ILoggerFactory factory) {
try {
ProtectionDomain protectionDomain = factory.getClass().getProtectionDomain();
CodeSource codeSource = protectionDomain.getCodeSource();
if (codeSource != null) {
return codeSource.getLocation();
}
}
catch (SecurityException ex) {
// Unable to determine location
}
return "unknown location";
}
@Override
public void setLogLevel(String loggerName, LogLevel level) {
ILoggerFactory factory = StaticLoggerBinder.getSingleton().getLoggerFactory();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment