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.
This commit is contained in:
committed by
Juergen Hoeller
parent
e53cce0778
commit
dee12db50a
@@ -148,14 +148,19 @@ public class ClassPathResource extends AbstractFileResolvingResource {
|
||||
*/
|
||||
@Nullable
|
||||
protected URL resolveURL() {
|
||||
if (this.clazz != null) {
|
||||
return this.clazz.getResource(this.path);
|
||||
try {
|
||||
if (this.clazz != null) {
|
||||
return this.clazz.getResource(this.path);
|
||||
}
|
||||
else if (this.classLoader != null) {
|
||||
return this.classLoader.getResource(this.path);
|
||||
}
|
||||
else {
|
||||
return ClassLoader.getSystemResource(this.path);
|
||||
}
|
||||
}
|
||||
else if (this.classLoader != null) {
|
||||
return this.classLoader.getResource(this.path);
|
||||
}
|
||||
else {
|
||||
return ClassLoader.getSystemResource(this.path);
|
||||
catch (IllegalArgumentException ex) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user