Skip to content

Commit 02e989c

Browse files
committed
Check that URL is actually a file URL before getting a File from it
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
1 parent 4c8729a commit 02e989c

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

spring-boot/src/main/java/org/springframework/boot/logging/log4j2/Log4J2LoggingSystem.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@
5858
*/
5959
public class Log4J2LoggingSystem extends Slf4JLoggingSystem {
6060

61+
private static final String FILE_PROTOCOL = "file";
62+
6163
private static final Map<LogLevel, Level> LEVELS;
6264

6365
static {
@@ -172,7 +174,7 @@ protected void loadConfiguration(String location, LogFile logFile) {
172174

173175
private ConfigurationSource getConfigurationSource(URL url) throws IOException {
174176
InputStream stream = url.openStream();
175-
if (ResourceUtils.isFileURL(url)) {
177+
if (FILE_PROTOCOL.equals(url.getProtocol())) {
176178
return new ConfigurationSource(stream, ResourceUtils.getFile(url));
177179
}
178180
return new ConfigurationSource(stream, url);

0 commit comments

Comments
 (0)