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/IContributionManager.java
*
     * @param id the contribution item id
     * @return the item that was found and removed, or <code>null</code> if none
     */
    public IContributionItem remove(String id);
    /**
     * Removes the given contribution item from the contribution items
     * known to this manager.
     *
     * @param item the contribution item
     * @return the <code>item</code> parameter if the item was removed,
     *   and <code>null</code> if it was not found
     */
    public IContributionItem remove(IContributionItem item);
    /**
     * Removes all contribution items from this manager.
     */
    public void removeAll();
    /**
     * Updates this manager's underlying widget(s) with any changes which
     * have been made to it or its items.  Normally changes to a contribution
     * manager merely mark it as dirty, without updating the underlying widgets.
     * This brings the underlying widgets up to date with any changes.
     *
     * @param force <code>true</code> means update even if not dirty,
     *   and <code>false</code> for normal incremental updating
     */
    public void update(boolean force);
}