Bug 552223

Summary: [cocoa] NPE in Menu._setVisible when clicking a menuitem of a disposed menu
Product: [Eclipse Project] Platform Reporter: Christoph Laeubrich <laeubi>
Component: SWTAssignee: Platform-SWT-Inbox <platform-swt-inbox>
Status: NEW --- QA Contact:
Severity: critical    
Priority: P3 CC: alexanderkerner24, lshanmug, niraj.modi, sravankumarl
Version: 4.13   
Target Milestone: ---   
Hardware: Macintosh   
OS: Mac OS X   
See Also: https://git.eclipse.org/r/151317
https://git.eclipse.org/c/platform/eclipse.platform.swt.git/commit/?id=1048abd609e00d1a2c6fec6c200b81ce02c32076
https://bugs.eclipse.org/bugs/show_bug.cgi?id=569593
Whiteboard:

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.