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

Deprecate finalization-related methods for removal

    XMLWordPrintable

    Details

    • Type: CSR
    • Status: Closed
    • Priority: P4
    • Resolution: Approved
    • Fix Version/s: 18
    • Component/s: core-libs
    • Labels:
      None
    • Compatibility Kind:
      source
    • Compatibility Risk:
      low
    • Compatibility Risk Description:
      Hide
      This change will have no runtime impact. Depending on a user's compilation settings, they may see new deprecation warnings (or errors, if warnings are treated as errors). Users who use @SuppressWarnings("deprecation") to avoid deprecation warnings for the finalize() method may start to see removal warnings instead, unless they change to @SuppressWarnings("removal").
      Show
      This change will have no runtime impact. Depending on a user's compilation settings, they may see new deprecation warnings (or errors, if warnings are treated as errors). Users who use @SuppressWarnings("deprecation") to avoid deprecation warnings for the finalize() method may start to see removal warnings instead, unless they change to @SuppressWarnings("removal").
    • Interface Kind:
      Java API
    • Scope:
      SE

      Description

      Summary

      Deprecate finalization-related methods for removal, per JEP 421 ("Deprecate Finalization for Removal").

      Problem

      Finalization has several critical, fundamental flaws. These were widely recognized early in Java's history, and the JDK has offered better alternatives for quite some time. JEP 421 deprecates finalization for removal. The deprecations should be reflected in the API specification.

      Solution

      Several finalize() methods are already ordinarily deprecated. They will be upgraded to terminal deprecation by adding forRemoval=true:

      • java.lang.Object.finalize()
      • java.lang.Enum.finalize()
      • java.awt.Graphics.finalize()
      • java.awt.PrintJob.finalize()
      • java.util.concurrent.ThreadPoolExecutor.finalize()
      • javax.imageio.spi.ServiceRegistry.finalize()
      • javax.imageio.stream.FileCacheImageInputStream.finalize()
      • javax.imageio.stream.FileImageInputStream.finalize()
      • javax.imageio.stream.FileImageOutputStream.finalize()
      • javax.imageio.stream.ImageInputStreamImpl.finalize()
      • javax.imageio.stream.MemoryCacheImageInputStream.finalize()

      Two methods will be newly deprecated with forRemoval=true:

      • java.lang.Runtime.runFinalization()
      • java.lang.System.runFinalization().

      One method will be newly deprecated with forRemoval=false:

      • java.lang.management.MemoryMXBean.getObjectPendingFinalizationCount().

      MemoryMXBean is an interface. Removing a method from it could adversely impact existing implementations. While developers should avoid using this method, it's safe to leave it in place. When finalization is disabled (or removed), this method will always return zero.

      Specification

      See attached webrev, also available at:

      http://cr.openjdk.java.net/~bchristi/8276748/webrev-CSR-03-8276748/

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              bchristi Brent Christian
              Reporter:
              bchristi Brent Christian
              Reviewed By:
              Stuart Marks
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: