Project: Eclipse_Platform_UI
Bug 404312 NPE in HandledContributionItem.canExecuteItem()
Reported: 2013-03-25 16:39:38 | Status: verified fixed

The javadoc for HandledContributionItem.getContext() states that it should return "the closest context, or global context if none in the hierarchy", but when it its getContextForParent() method delegates to ModelServiceImpl.getContainingContext(), which delegates to ModelUtils.getContainingContext(), it simply returns null when it can't find one in the hierarchy. This causes an NPE in HandledContributionItem.canExecuteItem(), which assumes a non-null context. See stack trace below: Thread [main] (Suspended (breakpoint at line 194 in ModelUtils)) ModelUtils.getContainingContext(MApplicationElement) line: 194 ModelServiceImpl.getContainingContext(MUIElement) line: 276 HandledContributionItem.getContextForParent(MUIElement) line: 852 HandledContributionItem.getContext(MUIElement) line: 866 HandledContributionItem.canExecuteItem(Event) line: 822 HandledContributionItem.access$2(HandledContributionItem, Event) line: 817 HandledContributionItem$3.run() line: 216 SafeRunner.run(ISafeRunnable) line: 42 HandledContributionItem.updateItemEnablement() line: 243 HandledContributionItem$ToolItemUpdateTimer.run() line: 146 Display.runTimer(int) line: 4270 Display.messageProc(int, int, int, int) line: 3357 OS.DispatchMessageW(MSG) line: not available [native method] OS.DispatchMessage(MSG) line: 2546 Display.readAndDispatch() line: 3756 PartRenderingEngine$9.run() line: 1029 Realm.runWithDefault(Realm, Runnable) line: 332 PartRenderingEngine.run(MApplicationElement, IEclipseContext) line: 923 E4Workbench.createAndRunUI(MApplicationElement) line: 86 Workbench$5.run() line: 588 Realm.runWithDefault(Realm, Runnable) line: 332 Workbench.createAndRunWorkbench(Display, WorkbenchAdvisor) line: 543 PlatformUI.createAndRunWorkbench(Display, WorkbenchAdvisor) line: 149 IDEApplication.start(IApplicationContext) line: 124 EclipseAppHandle.run(Object) line: 196 EclipseAppLauncher.runApplication(Object) line: 110 EclipseAppLauncher.start(Object) line: 79 EclipseStarter.run(Object) line: 353 EclipseStarter.run(String[], Runnable) line: 180 NativeMethodAccessorImpl.invoke0(Method, Object, Object[]) line: not available [native method] NativeMethodAccessorImpl.invoke(Object, Object[]) line: not available DelegatingMethodAccessorImpl.invoke(Object, Object[]) line: not available Method.invoke(Object, Object...) line: not available Main.invokeFramework(String[], URL[]) line: 629 Main.basicRun(String[]) line: 584 Main.run(String[]) line: 1438 Main.main(String[]) line: 1414

Files changed in fix:
bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/CoolBarToTrimManager.java