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

Bug 323198

Summary: CCE thrown in RepositoryAction from invoking IEvaluationContext's getVariable(String)
Product: [Technology] EGit Reporter: Remy Suen <remy.suen>
Component: UIAssignee: Project Inbox <egit.ui-inbox>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: mathias.kinzler, pwebster
Version: 0.9.0   
Target Milestone: 0.9.0-M3   
Hardware: All   
OS: All   
Whiteboard:

Description Remy Suen CLA 2010-08-19 19:26:51 EDT
Got this while using EGit. The code looks like this...

IHandlerService hsr = (IHandlerService) PlatformUI.getWorkbench()
    .getActiveWorkbenchWindow().getService(IHandlerService.class);
IEvaluationContext ctx = hsr.getCurrentState();
selection = (ISelection) ctx.getVariable(ISources.ACTIVE_MENU_SELECTION_NAME);

java.lang.ClassCastException: java.lang.Object cannot be cast to org.eclipse.jface.viewers.ISelection
at org.eclipse.egit.ui.internal.actions.RepositoryAction.getSelection(RepositoryAction.java:71)
at org.eclipse.egit.ui.internal.actions.RepositoryAction.run(RepositoryAction.java:94)
at org.eclipse.ui.internal.PluginAction.runWithEvent(PluginAction.java:251)
at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:584)
at org.eclipse.jface.action.ActionContributionItem.access$2(ActionContributionItem.java:501)
at org.eclipse.jface.action.ActionContributionItem$5.handleEvent(ActionContributionItem.java:411)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4066)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3657)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$4.run(PartRenderingEngine.java:724)
Comment 1 Paul Webster CLA 2010-08-19 19:52:58 EDT
In eclipse we return IEvaluationContext.UNDEFINED_VARIABLE (or something to that effect) when variables are "null".

In this case, if the context menu is not provided a selection, or if this code is called outside of a popup menu showing.

PW
Comment 2 Remy Suen CLA 2010-08-19 22:12:55 EDT
(In reply to comment #1)
> In eclipse we return IEvaluationContext.UNDEFINED_VARIABLE (or something to
> that effect) when variables are "null".

Mm...I actually just got the exception while working on EGit in 3.x. I have not been able to reproduce it at the moment though.
Comment 3 Remy Suen CLA 2010-08-25 07:03:07 EDT
I think there is probably still a source provider issue in 4.x but EGit should add an instanceof check to their code instead of arbitrarily downcasting.
Comment 4 Remy Suen CLA 2010-08-25 07:12:45 EDT
Please also fix the code in RepositoryActionHandler.
Comment 5 Mathias Kinzler CLA 2010-08-25 07:41:30 EDT
Code review at http://egit.eclipse.org/r/#change,1412
Comment 6 Mathias Kinzler CLA 2010-08-25 12:51:43 EDT
First one is merged as 51fab2f07155099d6ee08986f6c1d8dc1f67b0af, but we need another round: http://egit.eclipse.org/r/#change,1419
Comment 7 Mathias Kinzler CLA 2010-09-08 04:22:29 EDT
Merged as 0f65928171227869936e05703709ec00e7ef3f89