jdk/src/share/classes/sun/misc/URLClassPath.java
changeset 7980 3af394bb6f59
parent 5506 202f599c92aa
child 9035 1255eb81cc2f
--- a/jdk/src/share/classes/sun/misc/URLClassPath.java	Wed Jan 12 14:40:36 2011 +0000
+++ b/jdk/src/share/classes/sun/misc/URLClassPath.java	Thu Jan 13 11:01:30 2011 +0000
@@ -466,6 +466,7 @@
      */
     private static class Loader implements Closeable {
         private final URL base;
+        private JarFile jarfile; // if this points to a jar file
 
         /*
          * Creates a new Loader for the specified URL.
@@ -530,6 +531,17 @@
                 }
                 uc = url.openConnection();
                 InputStream in = uc.getInputStream();
+                if (uc instanceof JarURLConnection) {
+                    /* JarURLConnection.getInputStream() returns a separate
+                     * instance on each call. So we have to close this here.
+                     * The jar file cache will keep the file open.
+                     * Also, need to remember the jar file so it can be closed
+                     * in a hurry.
+                     */
+                    JarURLConnection juc = (JarURLConnection)uc;
+                    jarfile = juc.getJarFile();
+                    in.close();
+                }
             } catch (Exception e) {
                 return null;
             }
@@ -559,7 +571,11 @@
          * close this loader and release all resources
          * method overridden in sub-classes
          */
-        public void close () throws IOException {}
+        public void close () throws IOException {
+            if (jarfile != null) {
+                jarfile.close();
+            }
+        }
 
         /*
          * Returns the local class path for this loader, or null if none.