Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8212198

Remove Finalize methods from ZipFile, Inflater and Deflater

    Details

    • Type: CSR
    • Status: Closed
    • Priority: P3
    • Resolution: Approved
    • Fix Version/s: 12
    • Component/s: core-libs
    • Labels:
      None
    • Subcomponent:
    • Compatibility Kind:
      source, behavioral
    • Compatibility Risk:
      low
    • Compatibility Risk Description:
      Hide
      The finalize method has been deprecated. It is implemented as a no-op. Subclasses that override finalize in order to perform cleanup should be modified to use alternative cleanup mechanisms and to remove the overriding finalize method.

      The removal of the finalize methods will expose Object.finalize to subclasses of ZipFile, Deflater, and Inflater. Compilation errors may occur on the override of finalize due to the change in declared exceptions. Object.finalize is declared to throw java.lang.Throwable; previously only java.io.IOException was declared.
      Show
      The finalize method has been deprecated. It is implemented as a no-op. Subclasses that override finalize in order to perform cleanup should be modified to use alternative cleanup mechanisms and to remove the overriding finalize method. The removal of the finalize methods will expose Object.finalize to subclasses of ZipFile, Deflater, and Inflater. Compilation errors may occur on the override of finalize due to the change in declared exceptions. Object.finalize is declared to throw java.lang.Throwable; previously only java.io.IOException was declared.
    • Interface Kind:
      Java API
    • Scope:
      SE

      Description

      Summary

      Remove Finalize methods from ZipFile, Inflater and Deflater

      Problem

      The finalize methods of ZipFile, Inflater and Deflater were deprecated for removal in JDK 9 and should be removed.

      Solution

      The finalize methods will be removed from ZipFile, Deflator, and Inflator. As of JDK 9, these methods are no-ops.

      Prior to JDK 9:

      • ZipFile::finalize would call the close method. The recommendation has been to explicitly call close or use try-with-resources to close files. With this change the ZipFile close method will no longer be called when a ZipFile is found to be unreachable.

      • The Inflator::finalize and Deflator::finalize methods would call the end method. The recommended cleanup for a compressor is to explicitly call then end method when it is no longer in use. If the end is not invoked explicitly the resource of the compressor will be released when the instance becomes unreachable.

      Specification

      java.util.zip.ZipFile

      Remove the Implementation Note:

      If this ZipFile has been subclassed and the close method has been overridden, the close method will be called by the finalization when ZipFile is unreachable. But the subclasses should not depend on this specific implementation; the finalization is not reliable and the finalize method is deprecated to be removed.

      and removes the method:

      protected void finalize() throws IOException {}

      java.util.zip.Deflater:

      Remove the Implementation Note:

      If this Deflater has been subclassed and the end method has been overridden, the end method will be called by the finalization when the deflater is unreachable. But the subclasses should not depend on this specific implementation; the finalization is not reliable and the finalize method is deprecated to be removed.

      and removes the method:

      protected void finalize() throws IOException {}

      java.util.zip.Inflater:

      Remove the Implementation Note:

      If this Inflater has been subclassed and the end method has been overridden, the end method will be called by the finalization when the inflater is unreachable. But the subclasses should not depend on this specific implementation; the finalization is not reliable and the finalize method is deprecated to be removed.

      and removes the method:

      protected void finalize() throws IOException {}

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                lancea Lance Andersen
                Reporter:
                sherman Xueming Shen
                Reviewed By:
                Roger Riggs
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: