Skip to content

Commit dee12db

Browse files
candrewsjhoeller
authored andcommitted
getResource can throw IllegalArgumentException
Class.getResource, ClassLoader.getResource, and ClassLoader.getSystemResource will throw IllegalArgumentException if a malformed URL is provided to them. According to its javadoc, resolveURL should return null if not resolvable, so catch the IllegalArgumentException and return null.
1 parent e53cce0 commit dee12db

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

spring-core/src/main/java/org/springframework/core/io/ClassPathResource.java

+12-7
Original file line numberDiff line numberDiff line change
@@ -148,14 +148,19 @@ public boolean exists() {
148148
*/
149149
@Nullable
150150
protected URL resolveURL() {
151-
if (this.clazz != null) {
152-
return this.clazz.getResource(this.path);
153-
}
154-
else if (this.classLoader != null) {
155-
return this.classLoader.getResource(this.path);
151+
try {
152+
if (this.clazz != null) {
153+
return this.clazz.getResource(this.path);
154+
}
155+
else if (this.classLoader != null) {
156+
return this.classLoader.getResource(this.path);
157+
}
158+
else {
159+
return ClassLoader.getSystemResource(this.path);
160+
}
156161
}
157-
else {
158-
return ClassLoader.getSystemResource(this.path);
162+
catch (IllegalArgumentException ex) {
163+
return null;
159164
}
160165
}
161166

0 commit comments

Comments
 (0)