RFR: 8196586: Remove use of deprecated finalize methods from javafx property objects
kcr at openjdk.java.net
Thu Feb 20 20:06:40 UTC 2020
On Thu, 20 Feb 2020 07:10:11 GMT, Nir Lisker <nlisker at openjdk.org> wrote:
>>> > the referent to the created property object has been garbage collected before the `finalize` method is called
>>> I'm confused. What is that referent exactly and why is it guaranteed to have been GC'd before finalization?
>> I meant the referent of the `WeakReference` to the constructed `Property` object on which the `finalize` method is being called.
>> The `asObject` and `xxxxxProperty` methods create a bidirectional binding, which uses weak references to both the original `Property` object and the newly constructed `Property` object. The `finalize` method is on the newly-constructed `Property`. By the time that finalize method is called, the JVM guarantees that no other reference to that `Property` object exists. From the API docs of `Object::finalize`:
>> _The general contract of finalize is that it is invoked if and when the Java™ virtual machine has determined that there is no longer any means by which this object can be accessed by any thread that has not yet died, except as a result of an action taken by the finalization of some other object or class which is ready to be finalized._
> The logic seems correct. The weak reference to the newly created property in the bidirectional binding must be cleared before `finalize` is called. The unbinding attempt only interferes with GC.
> I still have to go over the tests.
> I note that with the removal of the finalize methods, the method `BidirectionalBinding#unbindNumber` is left unused and can be removed.
> Also, the changed property classes and `BidirectionalBinding` can use some cleanup that I can do after this is fixed, so I can remove that method at that time if you don't want to do it here.
> I note that with the removal of the finalize methods, the method BidirectionalBinding#unbindNumber is left unused and can be removed.
Good catch. I'll remove that method as part of this fix, since it is directly related. Any other cleanup can be done later.
More information about the openjfx-dev