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

(ref) Object.finalize should include note on alternatives to finalizers and link to the ref package

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 6u10
    • core-libs
    • x86
    • windows_xp

      FULL PRODUCT VERSION :
      java version "1.6.0_18"
      Java(TM) SE Runtime Environment (build 1.6.0_18-b07)
      Java HotSpot(TM) Client VM (build 16.0-b13, mixed mode, sharing)


      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows XP [Verze 5.1.2600]

      A DESCRIPTION OF THE PROBLEM :
      Please, decide, if Object.finalize() is deprecated or not, and change Javadoc

      http://java.sun.com/javase/6/docs/api/java/lang/Object.html#finalize%28%29

      to Object.finalize() method. Warn, that this method may be dangerous and shoudl be avoided. E.g. see http://mindprod.com/jgloss/finalize.html

      "Some feel finalize should be deprecated, and you should use phantom
      references instead since they give much better performance. Finalizers
      interfere with garbage collection. Their main use is debugging. Use
      them to issue an error message is an object is garbage collected
      without its close(), dispose(), disconnect()... method being called. "

      (It would be nice, if the Javadoc of Object.finalize() contains a link to an article teaching how to use PhantomReferences instead of Object.finalize() ).

      Also, clean sources of JDK/JRE from finalize() where it is possible. (Just simple grep of the code will show you where it is used.) There are already bugs for certain clases: 6299405, 6299405, 6353493. But there are still many more classes using finalize().


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Changed Javadoc. No, or almost no, finalize() in JRE source code.
      ACTUAL -
      Jvadoc says: "he usual purpose of finalize, however, is to perform cleanup actions before the object is irrevocably discarded. For example, the finalize method for an object that represents an input/output connection might perform explicit I/O transactions to break the connection before the object is permanently discarded. "

      REPRODUCIBILITY :
      This bug can be reproduced always.

            Unassigned Unassigned
            ryeung Roger Yeung (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: