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

Remove Finalize methods from FileInputStream and FileOutputStream

    XMLWordPrintable

Details

    • CSR
    • Status: Closed
    • P3
    • Resolution: Approved
    • 12
    • core-libs
    • None
    • source, behavioral
    • low
    • Hide
      Subclasses of FileInputStream and FileOutputStream that override close may observe that close is no longer called when the objects are found to be unreachable.
      The removal of the finalize methods will expose Object.finalize to subclasses of FileInputStream and FileOutputStream. 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
      Subclasses of FileInputStream and FileOutputStream that override close may observe that close is no longer called when the objects are found to be unreachable. The removal of the finalize methods will expose Object.finalize to subclasses of FileInputStream and FileOutputStream. 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.
    • Java API
    • SE

    Description

      Summary

      Remove the deprecated finalize methods of FileInputStream and FIleOutputStream.

      Problem

      The finalize methods of FileInputStream and FileOutputStream were deprecated for removal in JDK 9 and should be removed.

      Solution

      The finalize methods are removed.

      The java.lang.ref.Cleaner has been implemented since JDK 9 as the primary mechanism to close FileDescriptors no longer reachable from FileInputStream and FileOutputStreams.

      Previously, 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 FileInputStream or FileOutputStream close method will no longer be called when a FileInputstream or FileOutputStream is found to be unreachable.

      Specification

      java.io.FileInputStream removes:

      protected void finalize() throws IOException {}

      java.io.FileOutputStream removes:

      protected void finalize() throws IOException {}

      Attachments

        Issue Links

          Activity

            People

              rriggs Roger Riggs
              rriggs Roger Riggs
              Alan Bateman, Iris Clark, Lance Andersen, Mandy Chung
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: