ClassLoader.getResource can throw IllegalArgumentException#26574
Merged
jhoeller merged 1 commit intospring-projects:masterfrom Feb 25, 2021
Merged
ClassLoader.getResource can throw IllegalArgumentException#26574jhoeller merged 1 commit intospring-projects:masterfrom
jhoeller merged 1 commit intospring-projects:masterfrom
Conversation
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.
Contributor
Author
|
I believe that this issue is caused by a bug in Java. Quoting the javadoc of java.lang.ClassLoader.getResource(String):
In this case, "a URL could not be constructed to locate the resource" so null should be returned. But that's not what's happening. I've reported this issue at https://bugreport.java.com/ (internal review ID : 9069151) and openjdk/jdk#2662 |
jhoeller
added a commit
that referenced
this pull request
Feb 25, 2021
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. Closes gh-26574
3 tasks
This was referenced Mar 16, 2021
This was referenced Mar 17, 2021
Closed
lxbzmy
pushed a commit
to lxbzmy/spring-framework
that referenced
this pull request
Mar 26, 2022
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ClassLoader.getResourcecan throwIllegalArgumentExceptionif a malformed URL is provided to it.According to its javadoc,
resolveURLshould return null if not resolvable, so catch theIllegalArgumentExceptionand return null.Example stack trace produced by
new org.springframework.core.io.DefaultResourceLoader().getResource("C:/users/candrews/example").exists()