RFR: 8316931: [macos14] Test "java/awt/TrayIcon/ShowAfterDisposeTest/ShowAfterDisposeTest.html" throws and exception on Mac OS 14(x64, aarch64) [v4]
Sergey Bylokhov
serb at openjdk.org
Fri Jan 19 01:47:29 UTC 2024
On Thu, 18 Jan 2024 23:06:07 GMT, Phil Race <prr at openjdk.org> wrote:
>> I think the context became null because the component doesn't exist anymore
>
> Somehow we have null passed in.
> So something looked up appcontext and got null.
> Likely because some other code removed the app context from a map or similar.
> First step is to find exactly where that happened, then we can start to reason about how we managed to still post an event.
Note that it does not fail with NPE but instead this code trigger the bug:
AppContext eventContext = targetToAppContext(event.getSource());
if (eventContext != null && !eventContext.equals(appContext)) {
throw new RuntimeException("Event posted on wrong app context : " + event);
}
The source of the event is TrayIcon, and the appconteext for it is non-null as well.
This is the code where we post an event:
@Override
public void dispose() {
dummyFrame.dispose();
if (popup != null) {
popup.removeNotify();
}
LWCToolkit.targetDisposedPeer(target, this);
target = null;
super.dispose();
}
private void postEvent(final AWTEvent event) {
SunToolkit.executeOnEventHandlerThread(target, new Runnable() {
public void run() {
SunToolkit.postEvent(SunToolkit.targetToAppContext(target), event);
}
});
}
Note that we also call SunToolkit.targetToAppContext(target), and the target should be a TrayIcon and have a non-null appcontext, because later we successfully fetch it.
So the problem here is not in the null appcontext, but that we set target to null in the peer in dispose(), at the time we still processing the events.
- So we should check how all this should be synchronized, to prevent such race
- Or we should not set target to null, this is why the bug is not reproduced on other platforms.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/17329#discussion_r1458182051
More information about the client-libs-dev
mailing list