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
This commit is contained in:
Andy Wilkinson 2016-06-30 15:55:22 +01:00
parent 4c8729a3f2
commit 02e989c863
1 changed files with 3 additions and 1 deletions

View File

@ -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<LogLevel, Level> 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);