-
Notifications
You must be signed in to change notification settings - Fork 5.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JDK-8262277: URLClassLoader.getResource throws undocumented IllegalArgumentException #2662
Conversation
Hi @candrews, welcome to this OpenJDK project and thanks for contributing! We do not recognize you as Contributor and need to ensure you have signed the Oracle Contributor Agreement (OCA). If you have not signed the OCA, please follow the instructions. Please fill in your GitHub username in the "Username" field of the application. Once you have signed the OCA, please let us know by writing If you already are an OpenJDK Author, Committer or Reviewer, please click here to open a new issue so that we can record that fact. Please use "Add GitHub user candrews" as summary for the issue. If you are contributing this work on behalf of your employer and your employer has signed the OCA, please let us know by writing |
Submitted a bug report at https://bugreport.java.com/ |
This one liner will reproduce this issue (you can easily use new java.net.URLClassLoader(new java.net.URL[]{new java.net.URL("https://repo1.maven.org/anything-that-ends-with-slash/")}).findResource("c:/windows"); The key parts to reproduce the issue are:
|
/signed |
Thank you! Please allow for up to two weeks to process your OCA, although it is usually done within one to two business days. Also, please note that pull requests that are pending an OCA check will not usually be evaluated, so your patience is appreciated! |
Webrevs
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to be a long standing bug, maybe goes all the way back to JDK 1.2. Are you planning to add a regression test?
Hi, Craig As Alan said, a regression test will be needed. At minimum, it should test a method that returns a URL, as well as a method that returns an Enumeration (which can also lead to an IAE, as I noted in the bug report). Also, though the compatibility risk is low, it would be good to include a CSR for this change to long-standing behavior. |
/csr needed |
@bchristi-git has indicated that a compatibility and specification (CSR) request is needed for this pull request. |
Also, the copyright year should be updated: 2019 -> 2021 |
Done! 👍
I've added a test.
Done! 👍
I'm trying to figure out how to create a CSR and I'm not having much luck. According to the CSR FAQs:
However, I don't have an account on https://bugs.openjdk.java.net so I can't do as instructed. How do I create the CSR? |
3f6a974
to
e456f88
Compare
Mailing list message from Brent Christian on core-libs-dev: On 3/4/21 1:16 PM, Craig Andrews wrote:
OK, yeah - I can create the CSR. If you can craft some content for the A recent CSR of a somewhat similar -Brent |
* @bug 8262277 | ||
* @summary Test to see if URLClassLoader.getResource and URLClassLoader.getResources | ||
* throw IllegalArgumentException | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer if the test checked that findResource returned null and that findResources returned an empty enumeration. I think we should be able to find a better name for the test too.
Do you really want the author tag in the test? I know they exist in some tests but they are impossible to remove, even when tests/code are significantly changed by someone else.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer if the test checked that findResource returned null and that findResources returned an empty enumeration.
I'll update the test accordingly.
think we should be able to find a better name for the test too.
Do you really want the author tag in the test? I know they exist in some tests but they are impossible to remove, even when tests/code are significantly changed by someone else.
I can rename the test class to be something descriptive and remove the @author
tag. I was following other tests which is why I did it this way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've made the changes you requested.
SummaryModify implementation of ProblemThe javadocs for SolutionModify the implementation of Compatibility RiskLow Compatibility Risk DescriptionIt is possible that some code is catching the undocumented |
test/jdk/java/net/URLClassLoader/FindResourceDoesNotThrowException.java
Outdated
Show resolved
Hide resolved
…IllegalArgumentException
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fix looks good. Brent has created a CSR. It seems unlikely that anyone is depending the long standing/broken behavior but it seems release note worthy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, thanks!
What's the next step in the process for this PR? |
You need to fix this error:
by changing the title of this PR to match the JBS title. Then you should be able to integrate it. |
Done - how's it look now? |
@candrews This change now passes all automated pre-integration checks. ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details. After integration, the commit message for the final commit will be:
You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been 286 new commits pushed to the
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details. As you do not have Committer status in this project an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@AlanBateman, @bchristi-git, @prsadhuk) but any other Committer may sponsor as well. ➡️ To flag this PR as ready for integration with the above commit message, type |
/contributor add @candrews |
@candrews Could not parse
|
You don't need to add yourself as a contributor. The only thing you need to do is integrate. Then it is ready to be sponsored. |
/integrate |
/sponsor |
@bchristi-git @candrews Since your change was applied there have been 292 commits pushed to the
Your commit was automatically rebased without conflicts. Pushed as commit 0c718ab. 💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored. |
java.net.URLClassLoader.getResource
can throw an undocumentedIllegalArgumentException
.According to the javadoc for the
getResource
andfindResource
methods, neither should be throwingIllegalArgumentException
- they should return null if the resource can't be resolved.Quoting the javadoc for
URLClassLoader.html#findResource
And quoting the javadoc for
ClassLoader.html#getResource
Neither mentions throwing
IllegalArgumentException
and both are clear that when URL can't be constructed,null
should be returned.Here's a stack trace:
Looking at
URLClassPath.findResource
Instead of throwing
IllegalArgumentException
, that line should simply returnnull
.A similar issue exists at
URLClassPath.getResource
Instead of throwing
IllegalArgumentException
, that line should simply returnnull
.Progress
Issue
Reviewers
Download
$ git fetch https://git.openjdk.java.net/jdk pull/2662/head:pull/2662
$ git checkout pull/2662