From 02e989c8636fb01612b7dd498a98430af50ab42c Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Thu, 30 Jun 2016 15:55:22 +0100 Subject: [PATCH] Check that URL is actually a file URL before getting a File from it MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously, Log4J2LoggingSystem used ResourceUtils.isFileURL(URL) to check that the URL of the configuration was suitable for accessing as a File. Unfortunately, this fails when the URL’s protocol is vfs or vfsfile as both return true and then fail when the URL is subsequently passed into ResourceUtils.getFile(URL). This commit switches to checking that the URL’s protocol is file, the only protocol that will allow getFile(URL) to succeed. Closes gh-6246 --- .../boot/logging/log4j2/Log4J2LoggingSystem.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/spring-boot/src/main/java/org/springframework/boot/logging/log4j2/Log4J2LoggingSystem.java b/spring-boot/src/main/java/org/springframework/boot/logging/log4j2/Log4J2LoggingSystem.java index f50c70eda2..3a050486ac 100644 --- a/spring-boot/src/main/java/org/springframework/boot/logging/log4j2/Log4J2LoggingSystem.java +++ b/spring-boot/src/main/java/org/springframework/boot/logging/log4j2/Log4J2LoggingSystem.java @@ -58,6 +58,8 @@ import org.springframework.util.StringUtils; */ public class Log4J2LoggingSystem extends Slf4JLoggingSystem { + private static final String FILE_PROTOCOL = "file"; + private static final Map LEVELS; static { @@ -172,7 +174,7 @@ public class Log4J2LoggingSystem extends Slf4JLoggingSystem { private ConfigurationSource getConfigurationSource(URL url) throws IOException { InputStream stream = url.openStream(); - if (ResourceUtils.isFileURL(url)) { + if (FILE_PROTOCOL.equals(url.getProtocol())) { return new ConfigurationSource(stream, ResourceUtils.getFile(url)); } return new ConfigurationSource(stream, url);