Bug 206179 [Contributions] null pointer referenced is not caught when adding an action/item to menu in org.eclipse.jface.action.ContributionManager
If an error in ApplicationActionBarAdivosor-class occurs the application is just terminated, but does not throw an exception on console, even not in debug mode. Example: Save Action. When the save action is not created in the RCP's ActionBarAdvisor, but tried to be added to the menu the application is just terminated. A possible solution might be the modification of the both add-methods in org.eclipse.jface.action.ContributionManager: /* * (non-Javadoc) Method declared on IContributionManager. */ public void add(IAction action) { try{ add(new ActionContributionItem(action)); } catch(NullPointerException e){ ILog log = Platform.getLog(JFaceActivator.getBundle()); String message = "The action element pointed to null."; //$NON-NLS-1$ log.log(new Status(IStatus.ERROR, String.valueOf(JFaceActivator.getBundle().getBundleId()), message,e )); } } /* * (non-Javadoc) Method declared on IContributionManager. */ public void add(IContributionItem item) { try{ if (allowItem(item)) { contributions.add(item); itemAdded(item); } } catch(NullPointerException e){ ILog log = Platform.getLog(JFaceActivator.getBundle()); String message = "The item has a null-reference"; //$NON-NLS-1$ log.log(new Status(IStatus.ERROR, String.valueOf(JFaceActivator.getBundle().getBundleId()), message,e )); } }
bundles/org.eclipse.jface/src/org/eclipse/jface/action/ContributionManager.java
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.eclipse.jface.util.Policy;
/**
 * Abstract base class for all contribution managers, and standard
 * implementation of <code>IContributionManager</code>. This class provides
 * functionality common across the specific managers defined by this framework.
 * <p>
 * This class maintains a list of contribution items and a dirty flag, both as
 * internal state. In addition to providing implementations of most
 * <code>IContributionManager</code> methods, this class automatically
 * coalesces adjacent separators, hides beginning and ending separators, and
 * deals with dynamically changing sets of contributions. When the set of
 * contributions does change dynamically, the changes are propagated to the
 * control via the <code>update</code> method, which subclasses must
 * implement.
 * </p>
 * <p>
 * Note: A <code>ContributionItem</code> cannot be shared between different
 * <code>ContributionManager</code>s.
 * </p>
 */
public abstract class ContributionManager implements IContributionManager {
	
	
	/**
	 * The list of contribution items.
	 */
	private List contributions = new ArrayList();