RFR: 8371128: NullPointerException occurs due to double cleanup of SwingNode [v2]

Andy Goryachev angorya at openjdk.org
Wed Nov 5 15:28:15 UTC 2025


On Wed, 5 Nov 2025 12:46:23 GMT, Kevin Rushforth <kcr at openjdk.org> wrote:

>> I don't quite understand..In 
>> 
>> 
>> private final EventHandler<FocusUngrabEvent> ungrabHandler = event -> {
>>     556         if (!skipBackwardUnrgabNotification) {
>>     557             if (lwFrame != null) {
>>     558                 postAWTEvent(
>>     559                     swNodeIOP.createUngrabEvent(lwFrame));
>>     560             }
>>     561         }
>>     562     };
>> 
>> we are checking for null lwFrame in FX thread and there's no thread switching so how can we have again null lwFrame?
>> In disposeLwFrame, we are checking for null lwFrame inside `SwingNodeHelper.runOnEDT` due to context switch but here no such thing is happening and is running in same thread, so I am not sure why and where to `check for null on the EDT before calling createUngrabEvent`
>
> @prsadhuk You are correct. There is no thread switching in that block (it's all on the FX app thread, which creates an event and then sends that created event to the EDT).
> 
> Go ahead and integrate this PR.

yes, the block is on the fx thread, but the value of lwFrame is modified on the EDT.
Instead of this code where check and use happens with the volatile lwFrame, it should instead get the value into a temp variable and use that.


var lw = lwFrame;
if(lw != null) {
  use(lw)
}


here is the scenario, the way I see it:

swing       fx
not null
            L557, not null
            (context switch)
sets to null
(context switch)
            L559, null


unlikely, but possible, I think.

-------------

PR Review Comment: https://git.openjdk.org/jfx/pull/1960#discussion_r2495058308


More information about the openjfx-dev mailing list