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:55:27 UTC 2024
On Fri, 19 Jan 2024 01:43:48 GMT, Sergey Bylokhov <serb at openjdk.org> wrote:
>> 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 as on Windows
> - Or call dispose on EDT like on Linux.
I think we should set the target once and use it forever.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/17329#discussion_r1458186579
More information about the client-libs-dev
mailing list