RFC: 8132359: JarURLConnection.getJarFile() resource leak when file is not found

Michael McMahon michael.x.mcmahon at oracle.com
Fri May 8 17:38:43 UTC 2020


On 08/05/2020 17:34, Daniel Fuchs wrote:
> Hi Alex,
>
> On 08/05/2020 15:35, Alex Kashchenko wrote:
>> On 05/06/2020 01:11 PM, Michael McMahon wrote:
>>> Hi,
>>>
>>> Yes, we've had some discussion about it internally, and while others 
>>> may
>>> yet have an opinion, I think this approach is a reasonable one, with 
>>> a spec change
>>> that captures the behavior.
>>
>> I've created a CSR for this issue listing the "return null" variant 
>> above and "disable cache" as alternatives:
>>
>> https://bugs.openjdk.java.net/browse/JDK-8244650
>>
>> The wording for getJarFile() specification currently doesn't specify 
>> what happens, when entry doesn't exist. If it is better to change 
>> this wording - I would appreciate a guidance on that.
>
> I believe some sort of spec change will be needed, if only to justify
> challenging the JCK. Currently, the proposed change trips the following
> test:
>
> TestCase: [JarURLConnectionT216] FAIL->getManifest() did not throw 
> expected IOException for 
> jar:file:/JCK-runtime-15/tests/api/java_net/JarURLConnection//jardir/T11.jar!/NOJARENTRY.class
>
> best regards,
>
> -- daniel
>
I agree. Even though the @throws appears to say an IOException is only 
thrown

if the connection to the JAR file fails, I think we should make it more 
explicit.

Something like:

diff -r 55e9cb6b23ec 
src/java.base/share/classes/java/net/JarURLConnection.java
--- a/src/java.base/share/classes/java/net/JarURLConnection.java Thu May 
07 10:54:18 2020 -0400
+++ b/src/java.base/share/classes/java/net/JarURLConnection.java Fri May 
08 18:36:06 2020 +0100
@@ -215,7 +215,8 @@
       *
       * @return the JAR file for this connection. If the connection is
       * a connection to an entry of a JAR file, the JAR file object is
-     * returned
+     * returned. The JAR file is also returned if the connection to
+     * an entry fails, but the JAR file itself is accessible.
       *
       * @throws    IOException if an IOException occurs while trying to
       * connect to the JAR file for this connection.


- Michael



More information about the net-dev mailing list