RFR: 8316931: [macos14] Test "java/awt/TrayIcon/ShowAfterDisposeTest/ShowAfterDisposeTest.html" throws and exception on Mac OS 14(x64, aarch64) [v4]

Alisen Chung achung at openjdk.org
Wed Jan 24 20:43:29 UTC 2024


On Fri, 19 Jan 2024 01:52:47 GMT, Sergey Bylokhov <serb at openjdk.org> wrote:

>> 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.

ok, i'll try removing the target = null

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

PR Review Comment: https://git.openjdk.org/jdk/pull/17329#discussion_r1465513295


More information about the client-libs-dev mailing list