Project: Eclipse_Platform_UI
Bug 315282 NPE in SaveHandler
Reported: 2010-06-01 15:20:01 | Status: resolved fixed

I have an @CanExecute method in the SaveHandler: @CanExecute boolean canExecute(@Named(IServiceConstants.ACTIVE_PART) MDirtyable dirtyable) It's being called with a null value, even though it doesn't have @Optional in front of it. I thought @Optional was necessary to allow null for a parameter (I may be wrong here). My canExecute(*) failed with an NPE: !ENTRY org.eclipse.osgi 4 0 2010-06-01 15:17:05.006 !MESSAGE Application error !STACK 1 org.eclipse.e4.core.di.InjectionException: java.lang.NullPointerException at org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:49) at org.eclipse.e4.core.internal.di.InjectorImpl.invokeUsingClass(InjectorImpl.java:178) at org.eclipse.e4.core.internal.di.InjectorImpl.invoke(InjectorImpl.java:159) at org.eclipse.e4.core.contexts.ContextInjectionFactory.invoke(ContextInjectionFactory.java:101) at org.eclipse.e4.core.commands.internal.HandlerServiceImpl.canExecute(HandlerServiceImpl.java:94) at org.eclipse.e4.workbench.ui.renderers.swt.MenuItemRenderer.setEnabled(MenuItemRenderer.java:200) at org.eclipse.e4.workbench.ui.renderers.swt.MenuItemRenderer.createWidget(MenuItemRenderer.java:185) at org.eclipse.e4.ui.workbench.swt.internal.PartRenderingEngine.createWidget(PartRenderingEngine.java:436) at org.eclipse.e4.ui.workbench.swt.internal.PartRenderingEngine.createGui(PartRenderingEngine.java:330) at org.eclipse.e4.ui.workbench.swt.internal.PartRenderingEngine.createGui(PartRenderingEngine.java:388) at org.eclipse.e4.workbench.ui.renderers.swt.SWTPartRenderer.processContents(SWTPartRenderer.java:57) at org.eclipse.e4.ui.workbench.swt.internal.PartRenderingEngine.createGui(PartRenderingEngine.java:342) at org.eclipse.e4.ui.workbench.swt.internal.PartRenderingEngine.createGui(PartRenderingEngine.java:388) at org.eclipse.e4.workbench.ui.renderers.swt.SWTPartRenderer.processContents(SWTPartRenderer.java:57) at org.eclipse.e4.ui.workbench.swt.internal.PartRenderingEngine.createGui(PartRenderingEngine.java:342) at org.eclipse.e4.workbench.ui.renderers.swt.WBWRenderer.processContents(WBWRenderer.java:456) at org.eclipse.e4.ui.workbench.swt.internal.PartRenderingEngine.createGui(PartRenderingEngine.java:342) at org.eclipse.e4.ui.workbench.swt.internal.PartRenderingEngine.createGui(PartRenderingEngine.java:388) at org.eclipse.e4.ui.workbench.swt.internal.PartRenderingEngine$3.run(PartRenderingEngine.java:493) at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332) at org.eclipse.e4.ui.workbench.swt.internal.PartRenderingEngine.run(PartRenderingEngine.java:457) at org.eclipse.e4.workbench.ui.internal.E4Workbench.createAndRunUI(E4Workbench.java:102) at org.eclipse.ui.internal.Workbench$3.run(Workbench.java:534) at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332) at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:520) at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149) at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:115) at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196) at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110) at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79) at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:369) at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:48) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37) at java.lang.reflect.Method.invoke(Method.java:600) at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:619) at org.eclipse.equinox.launcher.Main.basicRun(Main.java:574) at org.eclipse.equinox.launcher.Main.run(Main.java:1407) at org.eclipse.equinox.launcher.Main.main(Main.java:1383) Caused by: java.lang.NullPointerException at org.eclipse.e4.ui.internal.workbench.handlers.SaveHandler.canExecute(SaveHandler.java:30) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:48) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37) at java.lang.reflect.Method.invoke(Method.java:600) at org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:42) ... 39 more

Files changed in fix:
bundles/org.eclipse.e4.ui.services/src/org/eclipse/e4/ui/services/IServiceConstants.java