RFR 9: 8165641 : Deprecate Object.finalize

Stuart Marks stuart.marks at oracle.com
Mon Mar 13 22:57:25 UTC 2017


As Dr Deprecator, I approve of this change. :-)

One small comment. Deprecation warnings aren't issued at the use site of a 
deprecated API if the use site itself is deprecated. Thus, the @SuppressWarnings 
annotation isn't necessary in the following diff hunk:



--- old/src/java.base/share/classes/java/io/FileInputStream.java	2017-03-10 
16:10:45.735018307 -0500
+++ new/src/java.base/share/classes/java/io/FileInputStream.java	2017-03-10 
16:10:45.411187490 -0500
@@ -413,9 +413,13 @@
       * Ensures that the <code>close</code> method of this file input stream is
       * called when there are no more references to it.
       *
+     * @deprecated Finalization is deprecated and should not be used.
+     *             See {@link Object#finalize} for the explanation and 
recommended replacement.
       * @exception  IOException  if an I/O error occurs.
       * @see        java.io.FileInputStream#close()
       */
+    @Deprecated(since="9")
+    @SuppressWarnings("deprecation")
      protected void finalize() throws IOException {
          if ((fd != null) &&  (fd != FileDescriptor.in)) {
              /* if fd is shared, the references in FileDescriptor



There are several other similar occurrences.

Thanks,

s'marks



On 3/10/17 1:40 PM, Roger Riggs wrote:
> Finalizers are inherently problematic and their use can lead to performance issues,
> deadlocks, hangs, and other problematic behavior.
>
> The problems have been accumulating for many years and the first step to
> deprecate Object.finalize and the overrides in the JDK to communicate the
> issues, recommend alternatives, and motivate changes where finalization is
> currently used.
>
> The behavior of finalization nor any uses of finalize are not modified by this
> change.
> Most of the changes are to suppress compilation warnings within the JDK.
>
> Please review and comment.
>
> Webrev:
> http://cr.openjdk.java.net/~rriggs/webrev-finalize-deprecate-8165641/
>
> Issue:
>    https://bugs.openjdk.java.net/browse/JDK-8165641
>
> Thanks, Roger
>
>


More information about the core-libs-dev mailing list