Integrated: JDK-8262277: URLClassLoader.getResource throws undocumented IllegalArgumentException

2021-03-15 Thread Craig Andrews
On Sat, 20 Feb 2021 19:20:48 GMT, Craig Andrews 
 wrote:

> `java.net.URLClassLoader.getResource` can throw an undocumented 
> `IllegalArgumentException`.
> 
> According to the javadoc for the `getResource` and `findResource` methods, 
> neither should be throwing `IllegalArgumentException` - they should return 
> null if the resource can't be resolved.
> 
> Quoting the javadoc for 
> [`URLClassLoader.html#findResource`](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/net/URLClassLoader.html#findResource(java.lang.String))
>> Returns:
>> a URL for the resource, or null if the resource could not be found, or 
>> if the loader is closed.
> 
> And quoting the javadoc for 
> [`ClassLoader.html#getResource`](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/ClassLoader.html#getResource(java.lang.String))
>> Returns:
>> URL object for reading the resource; null if the resource could not be 
>> found, a URL could not be constructed to locate the resource, the resource 
>> is in a package that is not opened unconditionally, or access to the 
>> resource is denied by the security manager.
> 
> Neither mentions throwing `IllegalArgumentException` and both are clear that 
> when URL can't be constructed, `null` should be returned.
> 
> Here's a stack trace:
> java.lang.IllegalArgumentException: name
> at 
> java.base/jdk.internal.loader.URLClassPath$Loader.findResource(URLClassPath.java:600)
> at 
> java.base/jdk.internal.loader.URLClassPath.findResource(URLClassPath.java:291)
> at java.base/java.net.URLClassLoader$2.run(URLClassLoader.java:655)
> at java.base/java.net.URLClassLoader$2.run(URLClassLoader.java:653)
> at java.base/java.security.AccessController.doPrivileged(Native 
> Method)
> at 
> java.base/java.net.URLClassLoader.findResource(URLClassLoader.java:652)
> 
> Looking at 
> [`URLClassPath.findResource`](https://github.com/openjdk/jdk/blob/2b00367e1154feb2c05b84a11d62fb5750e46acf/src/java.base/share/classes/jdk/internal/loader/URLClassPath.java#L603)
> URL findResource(final String name, boolean check) {
> URL url;
> try {
> url = new URL(base, ParseUtil.encodePath(name, false));
> } catch (MalformedURLException e) {
> throw new IllegalArgumentException("name");
> }
> 
> Instead of throwing `IllegalArgumentException`, that line should simply 
> return `null`.
> 
> A similar issue exists at 
> [`URLClassPath.getResource`](https://github.com/openjdk/jdk/blob/2b00367e1154feb2c05b84a11d62fb5750e46acf/src/java.base/share/classes/jdk/internal/loader/URLClassPath.java#L639)
> URL findResource(final String name, boolean check) {
> URL url;
> try {
> url = new URL(base, ParseUtil.encodePath(name, false));
> } catch (MalformedURLException e) {
> throw new IllegalArgumentException("name");
> }
> 
> Instead of throwing `IllegalArgumentException`, that line should simply 
> return `null`.

This pull request has now been integrated.

Changeset: 0c718ab2
Author:Craig Andrews 
Committer: Brent Christian 
URL:   https://git.openjdk.java.net/jdk/commit/0c718ab2
Stats: 60 lines in 2 files changed: 57 ins; 0 del; 3 mod

8262277: URLClassLoader.getResource throws undocumented IllegalArgumentException

Reviewed-by: alanb, bchristi, psadhukhan

-

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


Re: RFR: JDK-8262277: URLClassLoader.getResource throws undocumented IllegalArgumentException [v5]

2021-03-15 Thread Craig Andrews
On Mon, 15 Mar 2021 16:26:35 GMT, Kevin Rushforth  wrote:

> You need to fix this error:
> 
> > Title mismatch between PR and JBS for issue JDK-8262277
> 
> 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?

-

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


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

2021-03-15 Thread Craig Andrews
On Tue, 9 Mar 2021 08:40:47 GMT, Prasanta Sadhukhan  
wrote:

>> Craig Andrews has refreshed the contents of this pull request, and previous 
>> commits have been removed. The incremental views will show differences 
>> compared to the previous content of the PR. The pull request contains one 
>> new commit since the last revision:
>> 
>>   JDK-8262277: java.net.URLClassLoader.getResource throws undocumented 
>> IllegalArgumentException
>
> Marked as reviewed by psadhukhan (Reviewer).

What's the next step in the process for this PR?

-

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


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

2021-03-05 Thread Craig Andrews
> `java.net.URLClassLoader.getResource` can throw an undocumented 
> `IllegalArgumentException`.
> 
> According to the javadoc for the `getResource` and `findResource` methods, 
> neither should be throwing `IllegalArgumentException` - they should return 
> null if the resource can't be resolved.
> 
> Quoting the javadoc for 
> [`URLClassLoader.html#findResource`](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/net/URLClassLoader.html#findResource(java.lang.String))
>> Returns:
>> a URL for the resource, or null if the resource could not be found, or 
>> if the loader is closed.
> 
> And quoting the javadoc for 
> [`ClassLoader.html#getResource`](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/ClassLoader.html#getResource(java.lang.String))
>> Returns:
>> URL object for reading the resource; null if the resource could not be 
>> found, a URL could not be constructed to locate the resource, the resource 
>> is in a package that is not opened unconditionally, or access to the 
>> resource is denied by the security manager.
> 
> Neither mentions throwing `IllegalArgumentException` and both are clear that 
> when URL can't be constructed, `null` should be returned.
> 
> Here's a stack trace:
> java.lang.IllegalArgumentException: name
> at 
> java.base/jdk.internal.loader.URLClassPath$Loader.findResource(URLClassPath.java:600)
> at 
> java.base/jdk.internal.loader.URLClassPath.findResource(URLClassPath.java:291)
> at java.base/java.net.URLClassLoader$2.run(URLClassLoader.java:655)
> at java.base/java.net.URLClassLoader$2.run(URLClassLoader.java:653)
> at java.base/java.security.AccessController.doPrivileged(Native 
> Method)
> at 
> java.base/java.net.URLClassLoader.findResource(URLClassLoader.java:652)
> 
> Looking at 
> [`URLClassPath.findResource`](https://github.com/openjdk/jdk/blob/2b00367e1154feb2c05b84a11d62fb5750e46acf/src/java.base/share/classes/jdk/internal/loader/URLClassPath.java#L603)
> URL findResource(final String name, boolean check) {
> URL url;
> try {
> url = new URL(base, ParseUtil.encodePath(name, false));
> } catch (MalformedURLException e) {
> throw new IllegalArgumentException("name");
> }
> 
> Instead of throwing `IllegalArgumentException`, that line should simply 
> return `null`.
> 
> A similar issue exists at 
> [`URLClassPath.getResource`](https://github.com/openjdk/jdk/blob/2b00367e1154feb2c05b84a11d62fb5750e46acf/src/java.base/share/classes/jdk/internal/loader/URLClassPath.java#L639)
> URL findResource(final String name, boolean check) {
> URL url;
> try {
> url = new URL(base, ParseUtil.encodePath(name, false));
> } catch (MalformedURLException e) {
> throw new IllegalArgumentException("name");
> }
> 
> Instead of throwing `IllegalArgumentException`, that line should simply 
> return `null`.

Craig Andrews has refreshed the contents of this pull request, and previous 
commits have been removed. The incremental views will show differences compared 
to the previous content of the PR. The pull request contains one new commit 
since the last revision:

  JDK-8262277: java.net.URLClassLoader.getResource throws undocumented 
IllegalArgumentException

-

Changes:
  - all: https://git.openjdk.java.net/jdk/pull/2662/files
  - new: https://git.openjdk.java.net/jdk/pull/2662/files/79869e78..944956c9

Webrevs:
 - full: https://webrevs.openjdk.java.net/?repo=jdk=2662=04
 - incr: https://webrevs.openjdk.java.net/?repo=jdk=2662=03-04

  Stats: 9 lines in 1 file changed: 3 ins; 0 del; 6 mod
  Patch: https://git.openjdk.java.net/jdk/pull/2662.diff
  Fetch: git fetch https://git.openjdk.java.net/jdk pull/2662/head:pull/2662

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


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

2021-03-05 Thread Craig Andrews
On Fri, 5 Mar 2021 23:35:46 GMT, Brent Christian  wrote:

>> Craig Andrews has refreshed the contents of this pull request, and previous 
>> commits have been removed. The incremental views will show differences 
>> compared to the previous content of the PR. The pull request contains one 
>> new commit since the last revision:
>> 
>>   JDK-8262277: java.net.URLClassLoader.getResource throws undocumented 
>> IllegalArgumentException
>
> test/jdk/java/net/URLClassLoader/FindResourceDoesNotThrowException.java line 
> 27:
> 
>> 25:  * @test
>> 26:  * @bug 8262277
>> 27:  * @summary Test to see if URLClassLoader.getResource and 
>> URLClassLoader.getResources
> 
> The summary mentions the get* methods, but the test calls the find* methods.  
> I think it would be good to test all four methods (getResource, getResources, 
> findResource, findResources), and update the summary e.g. "Test if 
> URLClassLoader throws IllegalArgumentException when getting or finding 
> resources."

Good point - thank you.

I've made the change and updated this PR accordingly.

-

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


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

2021-03-05 Thread Craig Andrews
On Thu, 4 Mar 2021 21:10:56 GMT, Craig Andrews 
 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 (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


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

2021-03-05 Thread Craig Andrews
On Fri, 5 Mar 2021 15:46:40 GMT, Craig Andrews 
 wrote:

>> test/jdk/java/net/URLClassLoader/TestBug8262277.java line 30:
>> 
>>> 28:  * @summary Test to see if URLClassLoader.getResource and 
>>> URLClassLoader.getResources
>>> 29:  * throw IllegalArgumentException
>>> 30:  */
>> 
>> 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.
>
>> 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.

I've made the changes you requested.

-

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


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

2021-03-05 Thread Craig Andrews
On Fri, 5 Mar 2021 15:42:11 GMT, Alan Bateman  wrote:

> 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.

-

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


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

2021-03-05 Thread Craig Andrews
> `java.net.URLClassLoader.getResource` can throw an undocumented 
> `IllegalArgumentException`.
> 
> According to the javadoc for the `getResource` and `findResource` methods, 
> neither should be throwing `IllegalArgumentException` - they should return 
> null if the resource can't be resolved.
> 
> Quoting the javadoc for 
> [`URLClassLoader.html#findResource`](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/net/URLClassLoader.html#findResource(java.lang.String))
>> Returns:
>> a URL for the resource, or null if the resource could not be found, or 
>> if the loader is closed.
> 
> And quoting the javadoc for 
> [`ClassLoader.html#getResource`](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/ClassLoader.html#getResource(java.lang.String))
>> Returns:
>> URL object for reading the resource; null if the resource could not be 
>> found, a URL could not be constructed to locate the resource, the resource 
>> is in a package that is not opened unconditionally, or access to the 
>> resource is denied by the security manager.
> 
> Neither mentions throwing `IllegalArgumentException` and both are clear that 
> when URL can't be constructed, `null` should be returned.
> 
> Here's a stack trace:
> java.lang.IllegalArgumentException: name
> at 
> java.base/jdk.internal.loader.URLClassPath$Loader.findResource(URLClassPath.java:600)
> at 
> java.base/jdk.internal.loader.URLClassPath.findResource(URLClassPath.java:291)
> at java.base/java.net.URLClassLoader$2.run(URLClassLoader.java:655)
> at java.base/java.net.URLClassLoader$2.run(URLClassLoader.java:653)
> at java.base/java.security.AccessController.doPrivileged(Native 
> Method)
> at 
> java.base/java.net.URLClassLoader.findResource(URLClassLoader.java:652)
> 
> Looking at 
> [`URLClassPath.findResource`](https://github.com/openjdk/jdk/blob/2b00367e1154feb2c05b84a11d62fb5750e46acf/src/java.base/share/classes/jdk/internal/loader/URLClassPath.java#L603)
> URL findResource(final String name, boolean check) {
> URL url;
> try {
> url = new URL(base, ParseUtil.encodePath(name, false));
> } catch (MalformedURLException e) {
> throw new IllegalArgumentException("name");
> }
> 
> Instead of throwing `IllegalArgumentException`, that line should simply 
> return `null`.
> 
> A similar issue exists at 
> [`URLClassPath.getResource`](https://github.com/openjdk/jdk/blob/2b00367e1154feb2c05b84a11d62fb5750e46acf/src/java.base/share/classes/jdk/internal/loader/URLClassPath.java#L639)
> URL findResource(final String name, boolean check) {
> URL url;
> try {
> url = new URL(base, ParseUtil.encodePath(name, false));
> } catch (MalformedURLException e) {
> throw new IllegalArgumentException("name");
> }
> 
> Instead of throwing `IllegalArgumentException`, that line should simply 
> return `null`.

Craig Andrews has refreshed the contents of this pull request, and previous 
commits have been removed. The incremental views will show differences compared 
to the previous content of the PR. The pull request contains one new commit 
since the last revision:

  JDK-8262277: java.net.URLClassLoader.getResource throws undocumented 
IllegalArgumentException

-

Changes:
  - all: https://git.openjdk.java.net/jdk/pull/2662/files
  - new: https://git.openjdk.java.net/jdk/pull/2662/files/e456f886..79869e78

Webrevs:
 - full: https://webrevs.openjdk.java.net/?repo=jdk=2662=03
 - incr: https://webrevs.openjdk.java.net/?repo=jdk=2662=02-03

  Stats: 107 lines in 2 files changed: 54 ins; 53 del; 0 mod
  Patch: https://git.openjdk.java.net/jdk/pull/2662.diff
  Fetch: git fetch https://git.openjdk.java.net/jdk pull/2662/head:pull/2662

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


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

2021-03-04 Thread Craig Andrews
> `java.net.URLClassLoader.getResource` can throw an undocumented 
> `IllegalArgumentException`.
> 
> According to the javadoc for the `getResource` and `findResource` methods, 
> neither should be throwing `IllegalArgumentException` - they should return 
> null if the resource can't be resolved.
> 
> Quoting the javadoc for 
> [`URLClassLoader.html#findResource`](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/net/URLClassLoader.html#findResource(java.lang.String))
>> Returns:
>> a URL for the resource, or null if the resource could not be found, or 
>> if the loader is closed.
> 
> And quoting the javadoc for 
> [`ClassLoader.html#getResource`](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/ClassLoader.html#getResource(java.lang.String))
>> Returns:
>> URL object for reading the resource; null if the resource could not be 
>> found, a URL could not be constructed to locate the resource, the resource 
>> is in a package that is not opened unconditionally, or access to the 
>> resource is denied by the security manager.
> 
> Neither mentions throwing `IllegalArgumentException` and both are clear that 
> when URL can't be constructed, `null` should be returned.
> 
> Here's a stack trace:
> java.lang.IllegalArgumentException: name
> at 
> java.base/jdk.internal.loader.URLClassPath$Loader.findResource(URLClassPath.java:600)
> at 
> java.base/jdk.internal.loader.URLClassPath.findResource(URLClassPath.java:291)
> at java.base/java.net.URLClassLoader$2.run(URLClassLoader.java:655)
> at java.base/java.net.URLClassLoader$2.run(URLClassLoader.java:653)
> at java.base/java.security.AccessController.doPrivileged(Native 
> Method)
> at 
> java.base/java.net.URLClassLoader.findResource(URLClassLoader.java:652)
> 
> Looking at 
> [`URLClassPath.findResource`](https://github.com/openjdk/jdk/blob/2b00367e1154feb2c05b84a11d62fb5750e46acf/src/java.base/share/classes/jdk/internal/loader/URLClassPath.java#L603)
> URL findResource(final String name, boolean check) {
> URL url;
> try {
> url = new URL(base, ParseUtil.encodePath(name, false));
> } catch (MalformedURLException e) {
> throw new IllegalArgumentException("name");
> }
> 
> Instead of throwing `IllegalArgumentException`, that line should simply 
> return `null`.
> 
> A similar issue exists at 
> [`URLClassPath.getResource`](https://github.com/openjdk/jdk/blob/2b00367e1154feb2c05b84a11d62fb5750e46acf/src/java.base/share/classes/jdk/internal/loader/URLClassPath.java#L639)
> URL findResource(final String name, boolean check) {
> URL url;
> try {
> url = new URL(base, ParseUtil.encodePath(name, false));
> } catch (MalformedURLException e) {
> throw new IllegalArgumentException("name");
> }
> 
> Instead of throwing `IllegalArgumentException`, that line should simply 
> return `null`.

Craig Andrews has refreshed the contents of this pull request, and previous 
commits have been removed. The incremental views will show differences compared 
to the previous content of the PR. The pull request contains one new commit 
since the last revision:

  JDK-8262277: java.net.URLClassLoader.getResource throws undocumented 
IllegalArgumentException

-

Changes:
  - all: https://git.openjdk.java.net/jdk/pull/2662/files
  - new: https://git.openjdk.java.net/jdk/pull/2662/files/3f6a974e..e456f886

Webrevs:
 - full: https://webrevs.openjdk.java.net/?repo=jdk=2662=02
 - incr: https://webrevs.openjdk.java.net/?repo=jdk=2662=01-02

  Stats: 53 lines in 1 file changed: 53 ins; 0 del; 0 mod
  Patch: https://git.openjdk.java.net/jdk/pull/2662.diff
  Fetch: git fetch https://git.openjdk.java.net/jdk pull/2662/head:pull/2662

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


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

2021-03-04 Thread Craig Andrews
> `java.net.URLClassLoader.getResource` can throw an undocumented 
> `IllegalArgumentException`.
> 
> According to the javadoc for the `getResource` and `findResource` methods, 
> neither should be throwing `IllegalArgumentException` - they should return 
> null if the resource can't be resolved.
> 
> Quoting the javadoc for 
> [`URLClassLoader.html#findResource`](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/net/URLClassLoader.html#findResource(java.lang.String))
>> Returns:
>> a URL for the resource, or null if the resource could not be found, or 
>> if the loader is closed.
> 
> And quoting the javadoc for 
> [`ClassLoader.html#getResource`](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/ClassLoader.html#getResource(java.lang.String))
>> Returns:
>> URL object for reading the resource; null if the resource could not be 
>> found, a URL could not be constructed to locate the resource, the resource 
>> is in a package that is not opened unconditionally, or access to the 
>> resource is denied by the security manager.
> 
> Neither mentions throwing `IllegalArgumentException` and both are clear that 
> when URL can't be constructed, `null` should be returned.
> 
> Here's a stack trace:
> java.lang.IllegalArgumentException: name
> at 
> java.base/jdk.internal.loader.URLClassPath$Loader.findResource(URLClassPath.java:600)
> at 
> java.base/jdk.internal.loader.URLClassPath.findResource(URLClassPath.java:291)
> at java.base/java.net.URLClassLoader$2.run(URLClassLoader.java:655)
> at java.base/java.net.URLClassLoader$2.run(URLClassLoader.java:653)
> at java.base/java.security.AccessController.doPrivileged(Native 
> Method)
> at 
> java.base/java.net.URLClassLoader.findResource(URLClassLoader.java:652)
> 
> Looking at 
> [`URLClassPath.findResource`](https://github.com/openjdk/jdk/blob/2b00367e1154feb2c05b84a11d62fb5750e46acf/src/java.base/share/classes/jdk/internal/loader/URLClassPath.java#L603)
> URL findResource(final String name, boolean check) {
> URL url;
> try {
> url = new URL(base, ParseUtil.encodePath(name, false));
> } catch (MalformedURLException e) {
> throw new IllegalArgumentException("name");
> }
> 
> Instead of throwing `IllegalArgumentException`, that line should simply 
> return `null`.
> 
> A similar issue exists at 
> [`URLClassPath.getResource`](https://github.com/openjdk/jdk/blob/2b00367e1154feb2c05b84a11d62fb5750e46acf/src/java.base/share/classes/jdk/internal/loader/URLClassPath.java#L639)
> URL findResource(final String name, boolean check) {
> URL url;
> try {
> url = new URL(base, ParseUtil.encodePath(name, false));
> } catch (MalformedURLException e) {
> throw new IllegalArgumentException("name");
> }
> 
> Instead of throwing `IllegalArgumentException`, that line should simply 
> return `null`.

Craig Andrews has refreshed the contents of this pull request, and previous 
commits have been removed. The incremental views will show differences compared 
to the previous content of the PR. The pull request contains one new commit 
since the last revision:

  JDK-8262277: java.net.URLClassLoader.getResource throws undocumented 
IllegalArgumentException

-

Changes:
  - all: https://git.openjdk.java.net/jdk/pull/2662/files
  - new: https://git.openjdk.java.net/jdk/pull/2662/files/d9506624..3f6a974e

Webrevs:
 - full: https://webrevs.openjdk.java.net/?repo=jdk=2662=01
 - incr: https://webrevs.openjdk.java.net/?repo=jdk=2662=00-01

  Stats: 3 lines in 1 file changed: 0 ins; 2 del; 1 mod
  Patch: https://git.openjdk.java.net/jdk/pull/2662.diff
  Fetch: git fetch https://git.openjdk.java.net/jdk pull/2662/head:pull/2662

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


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

2021-03-04 Thread Craig Andrews
On Wed, 3 Mar 2021 18:10:25 GMT, Brent Christian  wrote:

>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'll see what I can do  

> 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?

-

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


Re: RFR: 8262277: java.net.URLClassLoader.getResource throws undocumented IllegalArgumentException

2021-03-03 Thread Craig Andrews
On Sat, 20 Feb 2021 19:22:10 GMT, Craig Andrews 
 wrote:

>> _NOTE_: I've reported this issue at https://bugreport.java.com/ (internal 
>> review ID : 9069151)
>> 
>> `java.net.URLClassLoader.getResource` can throw an undocumented 
>> `IllegalArgumentException`.
>> 
>> According to the javadoc for the `getResource` and `findResource` methods, 
>> neither should be throwing `IllegalArgumentException` - they should return 
>> null if the resource can't be resolved.
>> 
>> Quoting the javadoc for 
>> [`URLClassLoader.html#findResource`](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/net/URLClassLoader.html#findResource(java.lang.String))
>>> Returns:
>>> a URL for the resource, or null if the resource could not be found, or 
>>> if the loader is closed.
>> 
>> And quoting the javadoc for 
>> [`ClassLoader.html#getResource`](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/ClassLoader.html#getResource(java.lang.String))
>>> Returns:
>>> URL object for reading the resource; null if the resource could not be 
>>> found, a URL could not be constructed to locate the resource, the resource 
>>> is in a package that is not opened unconditionally, or access to the 
>>> resource is denied by the security manager.
>> 
>> Neither mentions throwing `IllegalArgumentException` and both are clear that 
>> when URL can't be constructed, `null` should be returned.
>> 
>> Here's a stack trace:
>> java.lang.IllegalArgumentException: name
>> at 
>> java.base/jdk.internal.loader.URLClassPath$Loader.findResource(URLClassPath.java:600)
>> at 
>> java.base/jdk.internal.loader.URLClassPath.findResource(URLClassPath.java:291)
>> at java.base/java.net.URLClassLoader$2.run(URLClassLoader.java:655)
>> at java.base/java.net.URLClassLoader$2.run(URLClassLoader.java:653)
>> at java.base/java.security.AccessController.doPrivileged(Native 
>> Method)
>> at 
>> java.base/java.net.URLClassLoader.findResource(URLClassLoader.java:652)
>> 
>> Looking at 
>> [`URLClassPath.findResource`](https://github.com/openjdk/jdk/blob/2b00367e1154feb2c05b84a11d62fb5750e46acf/src/java.base/share/classes/jdk/internal/loader/URLClassPath.java#L603)
>> URL findResource(final String name, boolean check) {
>> URL url;
>> try {
>> url = new URL(base, ParseUtil.encodePath(name, false));
>> } catch (MalformedURLException e) {
>> throw new IllegalArgumentException("name");
>> }
>> 
>> Instead of throwing `IllegalArgumentException`, that line should simply 
>> return `null`.
>> 
>> A similar issue exists at 
>> [`URLClassPath.getResource`](https://github.com/openjdk/jdk/blob/2b00367e1154feb2c05b84a11d62fb5750e46acf/src/java.base/share/classes/jdk/internal/loader/URLClassPath.java#L639)
>> URL findResource(final String name, boolean check) {
>> URL url;
>> try {
>> url = new URL(base, ParseUtil.encodePath(name, false));
>> } catch (MalformedURLException e) {
>> throw new IllegalArgumentException("name");
>> }
>> 
>> Instead of throwing `IllegalArgumentException`, that line should simply 
>> return `null`.
>
> Submitted a bug report at https://bugreport.java.com/
> Received internal review ID : 9069151

This one liner will reproduce this issue (you can easily use `jshell` to run it 
and see the problem):
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:
1. The `URLClassLoader` URL must not start with `file:` or `jar:` and must end 
in `/`. See 
https://github.com/openjdk/jdk/blob/2b00367e1154feb2c05b84a11d62fb5750e46acf/src/java.base/share/classes/jdk/internal/loader/URLClassPath.java#L493
2. The string passed to `findResource` must not be a valid URL component. 
Windows paths (which include a `:` making them invalid URL components) are a 
common and easy way to see this error.

-

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


Re: RFR: 8262277: java.net.URLClassLoader.getResource throws undocumented IllegalArgumentException

2021-03-03 Thread Craig Andrews
On Sat, 20 Feb 2021 19:20:48 GMT, Craig Andrews 
 wrote:

> _NOTE_: I've reported this issue at https://bugreport.java.com/ (internal 
> review ID : 9069151)
> 
> `java.net.URLClassLoader.getResource` can throw an undocumented 
> `IllegalArgumentException`.
> 
> According to the javadoc for the `getResource` and `findResource` methods, 
> neither should be throwing `IllegalArgumentException` - they should return 
> null if the resource can't be resolved.
> 
> Quoting the javadoc for 
> [`URLClassLoader.html#findResource`](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/net/URLClassLoader.html#findResource(java.lang.String))
>> Returns:
>> a URL for the resource, or null if the resource could not be found, or 
>> if the loader is closed.
> 
> And quoting the javadoc for 
> [`ClassLoader.html#getResource`](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/ClassLoader.html#getResource(java.lang.String))
>> Returns:
>> URL object for reading the resource; null if the resource could not be 
>> found, a URL could not be constructed to locate the resource, the resource 
>> is in a package that is not opened unconditionally, or access to the 
>> resource is denied by the security manager.
> 
> Neither mentions throwing `IllegalArgumentException` and both are clear that 
> when URL can't be constructed, `null` should be returned.
> 
> Here's a stack trace:
> java.lang.IllegalArgumentException: name
> at 
> java.base/jdk.internal.loader.URLClassPath$Loader.findResource(URLClassPath.java:600)
> at 
> java.base/jdk.internal.loader.URLClassPath.findResource(URLClassPath.java:291)
> at java.base/java.net.URLClassLoader$2.run(URLClassLoader.java:655)
> at java.base/java.net.URLClassLoader$2.run(URLClassLoader.java:653)
> at java.base/java.security.AccessController.doPrivileged(Native 
> Method)
> at 
> java.base/java.net.URLClassLoader.findResource(URLClassLoader.java:652)
> 
> Looking at 
> [`URLClassPath.findResource`](https://github.com/openjdk/jdk/blob/2b00367e1154feb2c05b84a11d62fb5750e46acf/src/java.base/share/classes/jdk/internal/loader/URLClassPath.java#L603)
> URL findResource(final String name, boolean check) {
> URL url;
> try {
> url = new URL(base, ParseUtil.encodePath(name, false));
> } catch (MalformedURLException e) {
> throw new IllegalArgumentException("name");
> }
> 
> Instead of throwing `IllegalArgumentException`, that line should simply 
> return `null`.
> 
> A similar issue exists at 
> [`URLClassPath.getResource`](https://github.com/openjdk/jdk/blob/2b00367e1154feb2c05b84a11d62fb5750e46acf/src/java.base/share/classes/jdk/internal/loader/URLClassPath.java#L639)
> URL findResource(final String name, boolean check) {
> URL url;
> try {
> url = new URL(base, ParseUtil.encodePath(name, false));
> } catch (MalformedURLException e) {
> throw new IllegalArgumentException("name");
> }
> 
> Instead of throwing `IllegalArgumentException`, that line should simply 
> return `null`.

Submitted a bug report at https://bugreport.java.com/
Received internal review ID : 9069151

-

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


RFR: 8262277: java.net.URLClassLoader.getResource throws undocumented IllegalArgumentException

2021-03-03 Thread Craig Andrews
_NOTE_: I've reported this issue at https://bugreport.java.com/ (internal 
review ID : 9069151)

`java.net.URLClassLoader.getResource` can throw an undocumented 
`IllegalArgumentException`.

According to the javadoc for the `getResource` and `findResource` methods, 
neither should be throwing `IllegalArgumentException` - they should return null 
if the resource can't be resolved.

Quoting the javadoc for 
[`URLClassLoader.html#findResource`](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/net/URLClassLoader.html#findResource(java.lang.String))
> Returns:
> a URL for the resource, or null if the resource could not be found, or if 
> the loader is closed.

And quoting the javadoc for 
[`ClassLoader.html#getResource`](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/ClassLoader.html#getResource(java.lang.String))
> Returns:
> URL object for reading the resource; null if the resource could not be 
> found, a URL could not be constructed to locate the resource, the resource is 
> in a package that is not opened unconditionally, or access to the resource is 
> denied by the security manager.

Neither mentions throwing `IllegalArgumentException` and both are clear that 
when URL can't be constructed, `null` should be returned.

Here's a stack trace:
java.lang.IllegalArgumentException: name
at 
java.base/jdk.internal.loader.URLClassPath$Loader.findResource(URLClassPath.java:600)
at 
java.base/jdk.internal.loader.URLClassPath.findResource(URLClassPath.java:291)
at java.base/java.net.URLClassLoader$2.run(URLClassLoader.java:655)
at java.base/java.net.URLClassLoader$2.run(URLClassLoader.java:653)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at 
java.base/java.net.URLClassLoader.findResource(URLClassLoader.java:652)

Looking at 
[`URLClassPath.findResource`](https://github.com/openjdk/jdk/blob/2b00367e1154feb2c05b84a11d62fb5750e46acf/src/java.base/share/classes/jdk/internal/loader/URLClassPath.java#L603)
URL findResource(final String name, boolean check) {
URL url;
try {
url = new URL(base, ParseUtil.encodePath(name, false));
} catch (MalformedURLException e) {
throw new IllegalArgumentException("name");
}

Instead of throwing `IllegalArgumentException`, that line should simply return 
`null`.

A similar issue exists at 
[`URLClassPath.getResource`](https://github.com/openjdk/jdk/blob/2b00367e1154feb2c05b84a11d62fb5750e46acf/src/java.base/share/classes/jdk/internal/loader/URLClassPath.java#L639)
URL findResource(final String name, boolean check) {
URL url;
try {
url = new URL(base, ParseUtil.encodePath(name, false));
} catch (MalformedURLException e) {
throw new IllegalArgumentException("name");
}

Instead of throwing `IllegalArgumentException`, that line should simply return 
`null`.

-

Commit messages:
 - 8262277: java.net.URLClassLoader.getResource throws undocumented 
IllegalArgumentException

Changes: https://git.openjdk.java.net/jdk/pull/2662/files
 Webrev: https://webrevs.openjdk.java.net/?repo=jdk=2662=00
  Issue: https://bugs.openjdk.java.net/browse/JDK-8262277
  Stats: 4 lines in 1 file changed: 2 ins; 0 del; 2 mod
  Patch: https://git.openjdk.java.net/jdk/pull/2662.diff
  Fetch: git fetch https://git.openjdk.java.net/jdk pull/2662/head:pull/2662

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