Skip to content

Commit 0663282

Browse files
committed
Log4jConfigurer initLogging(location) throws FileNotFoundException for file URL as well
Issue: SPR-9725
1 parent 17b9bde commit 0663282

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

spring-core/src/main/java/org/springframework/util/Log4jConfigurer.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2014 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -35,8 +35,7 @@
3535
* <p>For web environments, the analogous Log4jWebConfigurer class can be found
3636
* in the web package, reading in its configuration from context-params in
3737
* {@code web.xml}. In a J2EE web application, log4j is usually set up
38-
* via Log4jConfigListener or Log4jConfigServlet, delegating to
39-
* Log4jWebConfigurer underneath.
38+
* via Log4jConfigListener, delegating to Log4jWebConfigurer underneath.
4039
*
4140
* @author Juergen Hoeller
4241
* @since 13.03.2003
@@ -65,6 +64,10 @@ public abstract class Log4jConfigurer {
6564
public static void initLogging(String location) throws FileNotFoundException {
6665
String resolvedLocation = SystemPropertyUtils.resolvePlaceholders(location);
6766
URL url = ResourceUtils.getURL(resolvedLocation);
67+
if (ResourceUtils.URL_PROTOCOL_FILE.equals(url.getProtocol()) && !ResourceUtils.getFile(url).exists()) {
68+
throw new FileNotFoundException("Log4j config file [" + resolvedLocation + "] not found");
69+
}
70+
6871
if (resolvedLocation.toLowerCase().endsWith(XML_FILE_EXTENSION)) {
6972
DOMConfigurator.configure(url);
7073
}
@@ -98,6 +101,7 @@ public static void initLogging(String location, long refreshInterval) throws Fil
98101
if (!file.exists()) {
99102
throw new FileNotFoundException("Log4j config file [" + resolvedLocation + "] not found");
100103
}
104+
101105
if (resolvedLocation.toLowerCase().endsWith(XML_FILE_EXTENSION)) {
102106
DOMConfigurator.configureAndWatch(file.getAbsolutePath(), refreshInterval);
103107
}

spring-core/src/main/java/org/springframework/util/ResourceUtils.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,8 @@ public static URL getURL(String resourceLocation) throws FileNotFoundException {
129129
URL url = (cl != null ? cl.getResource(path) : ClassLoader.getSystemResource(path));
130130
if (url == null) {
131131
String description = "class path resource [" + path + "]";
132-
throw new FileNotFoundException(
133-
description + " cannot be resolved to URL because it does not exist");
132+
throw new FileNotFoundException(description +
133+
" cannot be resolved to URL because it does not exist");
134134
}
135135
return url;
136136
}
@@ -169,9 +169,8 @@ public static File getFile(String resourceLocation) throws FileNotFoundException
169169
ClassLoader cl = ClassUtils.getDefaultClassLoader();
170170
URL url = (cl != null ? cl.getResource(path) : ClassLoader.getSystemResource(path));
171171
if (url == null) {
172-
throw new FileNotFoundException(
173-
description + " cannot be resolved to absolute file path " +
174-
"because it does not reside in the file system");
172+
throw new FileNotFoundException(description +
173+
" cannot be resolved to absolute file path because it does not exist");
175174
}
176175
return getFile(url, description);
177176
}

0 commit comments

Comments
 (0)