RFR: 8258777: SkinBase: add api to un-/register invalidation-/listChange listeners [v9]
Kevin Rushforth
kcr at openjdk.java.net
Sat Apr 17 14:26:39 UTC 2021
On Sat, 17 Apr 2021 13:44:07 GMT, Jeanette Winzenburg <fastegal at openjdk.org> wrote:
>> modules/javafx.controls/src/test/java/test/com/sun/javafx/scene/control/LambdaMultipleHandlerTest.java line 211:
>>
>>> 209: WeakReference<LambdaMultiplePropertyChangeListenerHandler> ref =
>>> 210: new WeakReference<>(new LambdaMultiplePropertyChangeListenerHandler());
>>> 211: ref.get().registerListChangeListener(items, consumer);
>>
>> This is fragile. It is possible, although unlikely, that the referent could be GCed between its construction in the previous statement (after which it goes out of scope), and this statement. If this rare event happened, it would cause an NPE here. I recommend to keep a local reference to the referent and then set it to null after this (and before the `attemptGC`).
>
> changed as suggested. I used a similar pattern in BehaviorMemoryTest - should I file a testbug to change it in the same way?
Yes, please file a new bug (not high priority, since it is a corner case). I took a look and there are a few other controls tests that use this pattern as well (BehaviorCleanupTest, ListViewTest, TabPaneTest, SkinCleanupTest, SkinLabeledCleanupTest, SkinMemoryLeakTest), so the new bug could cover fixing this for all of them.
-------------
PR: https://git.openjdk.java.net/jfx/pull/409
More information about the openjfx-dev
mailing list