Bug 552223 - [cocoa] NPE in Menu._setVisible when clicking a menuitem of a disposed menu
Summary: [cocoa] NPE in Menu._setVisible when clicking a menuitem of a disposed menu
Status: NEW
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 4.13   Edit
Hardware: Macintosh Mac OS X
: P3 critical with 1 vote (vote)
Target Milestone: ---   Edit
Assignee: Platform-SWT-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-10-18 11:36 EDT by Christoph Laeubrich CLA
Modified: 2020-12-09 12:14 EST (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Christoph Laeubrich CLA 2019-10-18 11:36:51 EDT
When a popup menu is open and then gets dispose, clicking on one of its items produces the following NPE and application exits:

> Exception in thread "main" java.lang.NullPointerException
>    at org.eclipse.swt.widgets.Menu._setVisible(Menu.java:268)
>    at org.eclipse.swt.widgets.Display.runPopups(Display.java:4157)
>    at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3699)
 
under Linux, the poupmenu simply disappears (haven't tested it on Windows yet). I'll provide a gerrit with a test snippet and further information soon.
Comment 1 Eclipse Genie CLA 2019-10-18 11:46:21 EDT
New Gerrit change created: https://git.eclipse.org/r/151317
Comment 2 Christoph Laeubrich CLA 2019-10-18 12:34:16 EDT
Here is how the bug can be reproduced:

1) run snippet Bug_552223_NPE_Menu_setVisible under macos
2) right click in the window, a poup-menu appears
3) if you click the item everything is fine and the follwoing output is generated:
> Item was clicked
> The menu is now disposed
4) if you wait longer (e.g. 10 seconds) before you click (menu must be keept open) and the click the menuitem the application terminates with:
> The menu is now disposed!
> Exception in thread "main" java.lang.NullPointerException
>    at org.eclipse.swt.widgets.Menu._setVisible(Menu.java:268)
>    at org.eclipse.swt.widgets.Display.runPopups(Display.java:4157)
>    at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3699)
>    at Bug_552223_NPE_Menu_setVisible.main(PopupTest.java:71)

Looking at the code, there seems to be special code to keep the window alive, but later on it seems that on dispose the display variable is cleared out, so the NPE occurs.

As I don't have deeper knowledge about the cocoa part and not an cocoa development environment available I can't provide a patch but hope the provided information is enough for someone of the core team to reproduce and fix this, let me know if any further information is required.
Comment 3 Christoph Laeubrich CLA 2019-11-17 06:02:36 EST
(In reply to Christoph Laeubrich from comment #0)
> haven't tested it on Windows

Under Windows the behavior is: Menu stays open, menuitems can be clicked without a problem.