Bug 79401 [ErrorHandling] Duplicate presentation of error messages
1) Create a simple project with a simple folder inside it. 2) In Windows Explorer, expand the project and select the folder in the left pane. 3) Back in the Navigator view, try to rename the project. -> Rename fails because it cannot rename because Windows won't let you delete a folder that is being viewed in Windows Explorer. This is expected. Platform core returns a MultiStatus of the following form: MultiStatus ("problems encountered moving resources") MultiStatus ("Copy successful, but problems occurred removing old resources") Status ("Could not delete: d:\eclipse\test2\simple") The UI Error dialog shows the following in the details area: Problems occurred renaming the selected resource. Problems encountered while moving resources. Copy successful, but problems occurred removing old resources Could not delete: d:\eclipse\test2\simple\abc. Copy successful, but problems occurred removing old resources Could not delete: d:\eclipse\test2\simple\abc. Notice that the child MultiStatus from core is displayed twice. The root of this duplication is WorkspaceAction.recordError: private void recordError(CoreException error) { if (errorStatus == null) errorStatus = new MultiStatus(IDEWorkbenchPlugin.IDE_WORKBENCH, IStatus.ERROR, getProblemsMessage(), error); errorStatus.merge(error.getStatus()); } Observe that it stores the CoreException in the MultiStatus, *and* adds the error's status as a child of the MultiStatus. The JFace ErrorDialog class, when presented with this MultiStatus, recursively prints all MultiStatus objects, and all statuses contained within CoreExceptions. Since this MultiStatus contains both the original MultiStatus and the CoreException that carried it, it will get printed twice. The suggested fix is to not include the CoreException in the MultiStatus in recordError: private void recordError(CoreException error) { if (errorStatus == null) errorStatus = new MultiStatus(IDEWorkbenchPlugin.IDE_WORKBENCH, IStatus.ERROR, getProblemsMessage(), null); errorStatus.merge(error.getStatus()); } I tested this fix, and it produced an error dialog containing: Problems occurred renaming the selected resource. Copy successful, but problems occurred removing old resources Could not delete: d:\eclipse\test2\simon\abc.
bundles/org.eclipse.ui.ide/extensions/org/eclipse/ui/actions/WorkspaceAction.java
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.internal.ide.IDEWorkbenchMessages;
import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin;
import org.eclipse.ui.internal.ide.StatusUtil;
import org.eclipse.ui.internal.progress.ProgressMonitorJobsDialog;
/**
 * The abstract superclass for actions which invoke commands 
 * implemented in org.eclipse.core.* on a set of selected resources.
 * 
 * It iterates over all selected resources; errors are collected and
 * displayed to the user via a problems dialog at the end of the operation.
 * User requests to cancel the operation are passed along to the core.
 * <p>
 * Subclasses must implement the following methods:
 * <ul>
 *   <li><code>invokeOperation</code> - to perform the operation on one of the 
 *      selected resources</li>
 *   <li><code>getOperationMessage</code> - to furnish a title for the progress
 *      dialog</li>
 * </ul>
 * </p>
 * <p>
 * Subclasses may override the following methods:
 * <ul>
 *   <li><code>shouldPerformResourcePruning</code> - reimplement to turn off</li>