RFR: JDK-8262277: java.net.URLClassLoader.getResource throws undocumented IllegalArgumentException [v4]

Craig Andrews github.com+194713+candrews at openjdk.java.net
Fri Mar 5 19:45:06 UTC 2021


On Thu, 4 Mar 2021 21:10:56 GMT, Craig Andrews <github.com+194713+candrews at openjdk.org> wrote:

>> Hi, Craig
>> The commented-out lines should be removed from the change.
>> 
>> 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<URL> (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.
>
>>The commented-out lines should be removed from the change.
> 
> Done! �� 
> 
>> 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).
> 
> I've added a test.
> 
>> Also, the copyright year should be updated: 2019 -> 2021
> 
> Done! �� 
> 
>> @bchristi-git has indicated that a [compatibility and specification](https://wiki.openjdk.java.net/display/csr/Main) (CSR) request is needed for this pull request.
>> @candrews please create a CSR request and add link to it in [JDK-8262277](https://bugs.openjdk.java.net/browse/JDK-8262277). This pull request cannot be integrated until the CSR request is approved.
> 
> I'm trying to figure out how to create a CSR and I'm not having much luck. According to the [CSR FAQs](https://wiki.openjdk.java.net/display/csr/CSR+FAQs):
>> Q: How do I create a CSR ?
> A: Do not directly create a CSR from the Create Menu. JIRA will let you do this right up until the moment you try to save it and find your typing was in vain.
> Instead you should go to the target bug, select "More", and from the drop down menu select "Create CSR". This is required to properly associate the CSR with the main bug, just as is done for backports.
> 
> 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?

# Summary
Modify implementation of `java.net.URLClassLoader` such that `findResource` and `java.net.URLClassLoader.html#findResources` do no longer throw undocumented `IllegalArgumentException`.

# Problem
The javadocs for [`URLClassLoader.html#findResource`](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/net/URLClassLoader.html#findResource(java.lang.String)) and [`java.net.URLClassLoader.html#findResources`](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/net/URLClassLoader.html#findResources(java.lang.String)) do not indicate that an `IllegalArgumentException` can be thrown. The implementation does throw such exceptions under specific conditions which, due to being undocumented, is unexpected behavior. The unexpected exception can cause incorrect behavior, particularly on Windows systems due to the Windows file system path format increasingly the likelihood of causing the unexpected exception. [An example of such a problem was discovered in Spring Framework necessitating a workaround.](https://github.com/spring-projects/spring-framework/pull/26574).

# Solution
Modify the implementation of `java.net.URLClassLoader` to not throw `IllegalArgumentException` when finding resources.

# Compatibility Risk
Low

# Compatibility Risk Description
It is possible that some code is catching the undocumented `IllegalArgumentException` and treating it in a specific way.

-------------

PR: https://git.openjdk.java.net/jdk/pull/2662


More information about the core-libs-dev mailing list