JDK-6922236 : (ref) Object.finalize should include note on alternatives to finalizers and link to the ref package
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.lang
  • Affected Version: 6u10
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2010-02-02
  • Updated: 2017-04-26
  • Resolved: 2017-04-26
Related Reports
Duplicate :  
Description
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.

Comments
EVALUATION Object.finalize has not been deprecated. There has some effort to remove finalizers from the JDK where it makes sense and helps performance. The submitter should track the specific bugs that are open to remove specific finalizers. The submitter also asks that Object.finalize link to an article teaching developers how to use the reference-object classes. There is some merit to adding a note to the spec that links to the ref package and provides a few guidelines on alternatives to finalizers. I'm therefore re-classifying this bug report as an RFE asking that Object.finalize include a paragraph on alternatives.
14-08-2010