Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 320989

Summary: NPE in CocoaUIHandler
Product: [Eclipse Project] e4 Reporter: Thomas Schindl <tom.schindl>
Component: UIAssignee: Project Inbox <e4.ui-inbox>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: bokowski, bsd
Version: 0.9   
Target Milestone: 4.1   
Hardware: PC   
OS: Mac OS X - Carbon (unsup.)   
Whiteboard:
Attachments:
Description Flags
patch
none
patch none

Description Thomas Schindl CLA 2010-07-27 06:21:00 EDT
This happened in my Tutorial-RCP when opening a second window and hitting CMD+Q.

!ENTRY org.eclipse.e4.ui.workbench 4 0 2010-07-27 12:18:00.823
!MESSAGE Internal Error
!STACK 0
java.lang.NullPointerException
	at org.eclipse.e4.ui.workbench.renderers.swt.cocoa.CocoaUIHandler.findAction(CocoaUIHandler.java:662)
	at org.eclipse.e4.ui.workbench.renderers.swt.cocoa.CocoaUIHandler.runAction(CocoaUIHandler.java:554)
	at org.eclipse.e4.ui.workbench.renderers.swt.cocoa.CocoaUIHandler.quitMenuItemSelected(CocoaUIHandler.java:725)
	at org.eclipse.e4.ui.workbench.renderers.swt.cocoa.CocoaUIHandler.actionProc(CocoaUIHandler.java:748)
	at org.eclipse.swt.internal.cocoa.OS.objc_msgSendSuper(Native Method)
	at org.eclipse.swt.widgets.Display.applicationSendEvent(Display.java:4582)
	at org.eclipse.swt.widgets.Display.applicationProc(Display.java:4659)
	at org.eclipse.swt.internal.cocoa.OS.objc_msgSend(Native Method)
	at org.eclipse.swt.internal.cocoa.NSApplication.sendEvent(NSApplication.java:115)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3274)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$4.run(PartRenderingEngine.java:713)
Comment 1 Thomas Schindl CLA 2010-07-27 06:34:23 EDT
Created attachment 175302 [details]
patch

This patch at least removes the NPE - A better fix for the future would probably be to disable the CMD+Q on windows who are not defining it or searching in the other windows
Comment 2 Boris Bokowski CLA 2010-07-27 08:51:16 EDT
You've attached a patch for a different issue.
Comment 3 Thomas Schindl CLA 2010-07-27 09:02:19 EDT
Created attachment 175308 [details]
patch

the correct one
Comment 4 Boris Bokowski CLA 2010-07-27 09:13:44 EDT
Could we avoid fixing this for 4.0 by telling users to not include the fragment if they don't have a main menu?
Comment 5 Thomas Schindl CLA 2010-07-27 09:19:13 EDT
Sure. It is not an issue in the SDK because there all windows have a menu or are childs the main window so it's not causing troubles there.

We should think about a better fix to disable the Quit-Action probably if a main-window has not menu.
Comment 6 Brian de Alwis CLA 2010-09-09 11:12:41 EDT
Sorry Tom, I missed this bug.  Good catch.

(In reply to comment #5)
> We should think about a better fix to disable the Quit-Action probably if a
> main-window has not menu.

I don't think we want to disable Quit if there's no corresponding menu item found though (meaning that Cmd-Q is ignored).  Though (separately) it would be good to make the pill conditional on the existence of the toggle-toolbar command.  I suppose we could make the hooking of each app-menu entry conditional on the existence of the corresponding command.  It's pretty unlikely that an app will create a command after the window has been created, right?

I'm actually wondering if we shouldn't rototill this code slightly anyways: the current flow follows the 3.x CocoahUIEnhancer which checks for actions; but as we're now command-focussed, we can change things up.  Currently on About/Preferences/Quit, we search through the menu items to find a menu item that either (1) has an elementId with the corresponding Eclipse IWorkbenchCommandConstants for about/preferences/quit or (2) is a HandledMenuItem with a command for the corresponding Eclipse IWorkbenchCommandConstants for about/preferences/quit.  We should instead just use the handler service to look for a handler for the appropriate command (and search from the active child).  If none is found, and there is a menu, then search the menus for a menu item with a matching elementId.

Does that make sense?
Comment 7 Paul Webster CLA 2010-09-13 07:49:21 EDT
(In reply to comment #6)
>> I'm actually wondering if we shouldn't rototill this code slightly anyways: the
> current flow follows the 3.x CocoahUIEnhancer which checks for actions; but as
> we're now command-focussed, we can change things up.  Currently on
> About/Preferences/Quit, we search through the menu items to find a menu item
> that either (1) has an elementId with the corresponding Eclipse
> IWorkbenchCommandConstants for about/preferences/quit or (2) is a
> HandledMenuItem with a command for the corresponding Eclipse
> IWorkbenchCommandConstants for about/preferences/quit.  We should instead just
> use the handler service to look for a handler for the appropriate command (and
> search from the active child).  If none is found, and there is a menu, then
> search the menus for a menu item with a matching elementId.

It would be better to simply delegate (through the command) to the handler.  This will work for about and quit.  I'm less sure about preferences.  In 3.x the dialog popped up by the preferences command is sometimes a view preference dialog (if the Problems view is active, for example).  I'm not sure what to do about that.

PW
Comment 8 Brian de Alwis CLA 2010-11-08 10:04:40 EST
Oops, I thought I had committed a fix for this.  Fix now committed.

I'll submit a different bug for the rework along the lines of comment 6 and comment 7.