JDK-7050028 : ISE "zip file closed" from JarURLConnection.getInputStream on JDK 7 when !useCaches
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.net
  • Affected Version: 7
  • Priority: P2
  • Status: Closed
  • Resolution: Fixed
  • OS: generic,linux
  • CPU: generic,x86
  • Submitted: 2011-05-31
  • Updated: 2013-05-14
  • Resolved: 2011-07-18
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 7
7 b146Fixed
Related Reports
Duplicate :  
Relates :  
Relates :  
Description
Compile and run the class given in http://netbeans.org/bugzilla/attachment.cgi?id=108629 using JDK 6. It prints

class Bug196716

as expected. Now run using JDK 7 b143; it throws

Exception in thread "main" java.lang.IllegalStateException: zip file closed
	at java.util.zip.ZipFile.ensureOpen(ZipFile.java:632)
	at java.util.zip.ZipFile.getInputStream(ZipFile.java:345)
	at java.util.jar.JarFile.getInputStream(JarFile.java:403)
	at sun.net.www.protocol.jar.JarURLConnection.getInputStream(JarURLConnection.java:162)
	at sun.misc.URLClassPath$Loader$1.getInputStream(URLClassPath.java:553)
	at sun.misc.Resource.cachedInputStream(Resource.java:77)
	at sun.misc.Resource.getByteBuffer(Resource.java:160)
	at java.net.URLClassLoader.defineClass(URLClassLoader.java:436)
	at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
	at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
	at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
	at Bug196716.main(Bug196716.java:36)

Comments
EVALUATION This arose due to the fix for 6896088, which then exposed the (long standing) problem in JarURLConnection.close(). Definitely for 8, we should fix the problem there. But, it might be less risk at this stage of 7 to go back to the fix for 6896088 and see if the call to JarURLConnection.close() can be removed. It doesn't appear to be necessary [to be verified].
01-06-2011

SUGGESTED FIX # HG changeset patch # Parent efbf75c24b0f31847c9c403f6dc07dc80551908d # User Jesse Glick <###@###.###> #7050028: ISE "zip file closed" from JarURLConnection.getInputStream on JDK 7 when !useCaches At least remember that the JarFile is closed after closing it. Better would be to not close it when it is going to be needed immediately afterwards anyway. diff --git a/src/share/classes/sun/net/www/protocol/jar/JarURLConnection.java b/src/share/classes/sun/net/www/protocol/jar/JarURLConnection.java --- a/src/share/classes/sun/net/www/protocol/jar/JarURLConnection.java +++ b/src/share/classes/sun/net/www/protocol/jar/JarURLConnection.java @@ -109,6 +109,7 @@ } finally { if (!getUseCaches()) { jarFile.close(); + connected = false; } } } @@ -134,6 +135,7 @@ try { if (!getUseCaches()) { jarFile.close(); + connected = false; } } catch (Exception e) { }
31-05-2011

EVALUATION The JAR file is closed here: at sun.net.www.protocol.jar.JarURLConnection$JarURLInputStream.close(JarURLConnection.java:111) at sun.misc.URLClassPath$Loader.getResource(URLClassPath.java:543) at sun.misc.URLClassPath.getResource(URLClassPath.java:195) at java.net.URLClassLoader$1.run(URLClassLoader.java:358) at java.net.URLClassLoader$1.run(URLClassLoader.java:355) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:354) at java.lang.ClassLoader.loadClass(ClassLoader.java:423) at java.lang.ClassLoader.loadClass(ClassLoader.java:356) at Bug196716.main(Bug196716.java:36)
31-05-2011

WORK AROUND Known workarounds: 1. Do not turn off URLConnection caches. 2. Use file:/x.jar URLs rather than jar:file:/x.jar!/ URLs for URLClassLoader.
31-05-2011

PUBLIC COMMENTS http://netbeans.org/bugzilla/show_bug.cgi?id=196716 is tracking issue for NetBeans.
31-05-2011