< prev index next >

src/java.base/share/classes/java/util/zip/ZipFile.java

Print this page

        

@@ -54,11 +54,10 @@
 import java.util.WeakHashMap;
 import java.util.function.Consumer;
 import java.util.function.Function;
 import java.util.function.IntFunction;
 import java.util.jar.JarEntry;
-import java.util.jar.JarFile;
 import java.util.stream.Stream;
 import java.util.stream.StreamSupport;
 import jdk.internal.misc.JavaLangAccess;
 import jdk.internal.misc.JavaUtilZipFileAccess;
 import jdk.internal.misc.SharedSecrets;

@@ -83,17 +82,10 @@
  * for the cleanup of resources acquired by the subclass. Subclasses that override
  * {@link #finalize()} in order to perform cleanup should be modified to use alternative
  * cleanup mechanisms such as {@link java.lang.ref.Cleaner} and remove the overriding
  * {@code finalize} method.
  *
- * @implSpec
- * If this {@code ZipFile} has been subclassed and the {@code close} method has
- * been overridden, the {@code close} method will be called by the finalization
- * when {@code ZipFile} is unreachable. But the subclasses should not depend on
- * this specific implementation; the finalization is not reliable and the
- * {@code finalize} method is deprecated to be removed.
- *
  * @author      David Connelly
  * @since 1.1
  */
 public
 class ZipFile implements ZipConstants, Closeable {

@@ -242,11 +234,11 @@
 
         this.zc = ZipCoder.get(charset);
         this.name = name;
         long t0 = System.nanoTime();
 
-        this.res = CleanableResource.get(this, file, mode);
+        this.res = new CleanableResource(this, file, mode);
 
         PerfCounter.getZipFileOpenTime().addElapsedTimeFrom(t0);
         PerfCounter.getZipFileCount().increment();
     }
 

@@ -823,48 +815,10 @@
             this.istreams = Collections.newSetFromMap(new WeakHashMap<>());
             this.inflaterCache = new ArrayDeque<>();
             this.zsrc = Source.get(file, (mode & OPEN_DELETE) != 0);
         }
 
-        /*
-         * If {@code ZipFile} has been subclassed and the {@code close} method is
-         * overridden, uses the {@code finalizer} mechanism for resource cleanup.
-         * So {@code close} method can be called when the the {@code ZipFile} is
-         * unreachable. This mechanism will be removed when {@code finalize} method
-         * is removed from {@code ZipFile}.
-         */
-        static CleanableResource get(ZipFile zf, File file, int mode)
-            throws IOException {
-            Class<?> clz = zf.getClass();
-            while (clz != ZipFile.class && clz != JarFile.class) {
-                if (JLA.getDeclaredPublicMethods(clz, "close").size() != 0) {
-                    return new FinalizableResource(zf, file, mode);
-                }
-                clz = clz.getSuperclass();
-            }
-            return new CleanableResource(zf, file, mode);
-        }
-
-        static class FinalizableResource extends CleanableResource {
-            ZipFile zf;
-            FinalizableResource(ZipFile zf, File file, int mode)
-                throws IOException {
-                super(file, mode);
-                this.zf = zf;
-            }
-
-            @Override
-            void clean() {
-                run();
-            }
-
-            @Override
-            @SuppressWarnings("deprecation")
-            protected void finalize() throws IOException {
-                zf.close();
-            }
-        }
     }
 
     /**
      * Closes the ZIP file.
      *

@@ -889,29 +843,10 @@
                 throw ioe.getCause();
             }
         }
     }
 
-    /**
-     * Ensures that the system resources held by this ZipFile object are
-     * released when there are no more references to it.
-     *
-     * @deprecated The {@code finalize} method has been deprecated and will be
-     *     removed. It is implemented as a no-op. Subclasses that override
-     *     {@code finalize} in order to perform cleanup should be modified to
-     *     use alternative cleanup mechanisms and to remove the overriding
-     *     {@code finalize} method. The recommended cleanup for ZipFile object
-     *     is to explicitly invoke {@code close} method when it is no longer in
-     *     use, or use try-with-resources. If the {@code close} is not invoked
-     *     explicitly the resources held by this object will be released when
-     *     the instance becomes unreachable.
-     *
-     * @throws IOException if an I/O error has occurred
-     */
-    @Deprecated(since="9", forRemoval=true)
-    protected void finalize() throws IOException {}
-
     private void ensureOpen() {
         if (closeRequested) {
             throw new IllegalStateException("zip file closed");
         }
         if (res.zsrc == null) {
< prev index next >