Project: Eclipse_Platform_UI
Bug 263690 [Commands] Command that can throw a CoreException during execution is considered successfully run
Reported: 2009-02-04 15:22:00 | Status: verified fixed

Using M5, I have a case where I try to start a command handler that will fail (I removed some required bundles on purpose). I was checking an error handling code. The problem is that the first time the command is run it looks like it is successful when it failed to terminate normally. Here is the stack trace I have: org.eclipse.core.runtime.CoreException: Plug-in org.eclipse.equinox.p2.ui.sdk was unable to load class org.eclipse.equinox.internal.p2.ui.sdk.InstallNewSoftwareHandler. at org.eclipse.core.internal.registry.osgi.RegistryStrategyOSGI.throwException(RegistryStrategyOSGI.java:180) at org.eclipse.core.internal.registry.osgi.RegistryStrategyOSGI.createExecutableExtension(RegistryStrategyOSGI.java:162) at org.eclipse.core.internal.registry.ExtensionRegistry.createExecutableExtension(ExtensionRegistry.java:874) at org.eclipse.core.internal.registry.ConfigurationElement.createExecutableExtension(ConfigurationElement.java:243) at org.eclipse.core.internal.registry.ConfigurationElementHandle.createExecutableExtension(ConfigurationElementHandle.java:51) at org.eclipse.ui.internal.handlers.HandlerProxy.loadHandler(HandlerProxy.java:335) at org.eclipse.ui.internal.handlers.HandlerProxy.execute(HandlerProxy.java:274) at org.eclipse.core.commands.Command.executeWithChecks(Command.java:476) at org.eclipse.pde.api.tools.ui.internal.preferences.ApiErrorsWarningsConfigurationBlock$4.mouseDown(ApiErrorsWarningsConfigurationBlock.java:1299) at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:179) at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1003) at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3877) at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3470) at org.eclipse.jface.window.Window.runEventLoop(Window.java:825) at org.eclipse.jface.window.Window.open(Window.java:801) at org.eclipse.ui.internal.OpenPreferencesAction.run(OpenPreferencesAction.java:65) at org.eclipse.jface.action.Action.runWithEvent(Action.java:498) I think the problem comes from: public final Object execute(final ExecutionEvent event) throws ExecutionException { if (loadHandler()) { if (!isEnabled()) { MessageDialog.openInformation(Util.getShellToParentOn(), WorkbenchMessages.Information, WorkbenchMessages.PluginAction_disabledMessage); return null; } return handler.execute(event); } return null; } where null is returned is the loading of the handler failed. loadHandler is swallowing the core exception. So the best thing to do is to replace the: return null; statement with a throw new ExecutionException(..); This will make sure that the user code can properly detect an execution failure. Steps to reproduce: 1) Define a new command handler that throws a CoreException 2) Run the corresponding command with a try/catch for all potential exceptions thrown by Command.executeWithChecks(..). 3) You won't hit any of the catch blocks on the first run.

Files changed in fix:
bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/handlers/HandlerProxy.java tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/commands/ExceptionThrowingHandler.java tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/commands/HandlerActivationTest.java tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/dynamicplugins/CommandsExtensionDynamicTest.java