Bug 166645 - NPE in TextEditorActionContributor when opening Ant editor
Summary: NPE in TextEditorActionContributor when opening Ant editor
Status: ASSIGNED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: Ant (show other bugs)
Version: 3.3   Edit
Hardware: PC Windows XP
: P3 normal with 1 vote (vote)
Target Milestone: ---   Edit
Assignee: Platform-Ant-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-12-04 10:56 EST by Markus Keller CLA
Modified: 2019-09-06 16:05 EDT (History)
2 users (show)

See Also:


Attachments
Fix (1.57 KB, patch)
2006-12-04 11:22 EST, Markus Keller CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Markus Keller CLA 2006-12-04 10:56:38 EST
I20061129-1340 + ZRH-plugins from 20061204-0928

- Open an Ant file with the Ant editor, e.g. test.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project name="testsuite" default="run" basedir=".">
	<target name="run">
	</target>
</project>

=> Error dialog and exception below. I'm not sure whose fault this is. AFAICS, the problem is that AntEditorActionContributor.contributeToMenu(IMenuManager) does not call super.contributeToMenu(menu) when it is first invoked. However, I didn't find a contract that would forbid reimplementing the method (and the Ant code has not been changed in 3.3.

I'll try to work around it in TextEditorActionContributor for now, but Dani will have to make the final decision.


Error
Mon Dec 04 15:24:53 CET 2006
Problems occurred when invoking code from plug-in: "org.eclipse.ui.workbench".

java.lang.NullPointerException
	at org.eclipse.ui.editors.text.TextEditorActionContributor.doSetActiveEditor(TextEditorActionContributor.java:106)
	at org.eclipse.ui.editors.text.TextEditorActionContributor.setActiveEditor(TextEditorActionContributor.java:131)
	at org.eclipse.ant.internal.ui.editor.AntEditorActionContributor.doSetActiveEditor(AntEditorActionContributor.java:69)
	at org.eclipse.ant.internal.ui.editor.AntEditorActionContributor.setActiveEditor(AntEditorActionContributor.java:145)
	at org.eclipse.ui.internal.EditorActionBars.partChanged(EditorActionBars.java:335)
	at org.eclipse.ui.internal.WorkbenchPage$3.run(WorkbenchPage.java:603)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:37)
	at org.eclipse.core.runtime.Platform.run(Platform.java:850)
	at org.eclipse.ui.internal.WorkbenchPage.activatePart(WorkbenchPage.java:592)
	at org.eclipse.ui.internal.WorkbenchPage.setActivePart(WorkbenchPage.java:3179)
	at org.eclipse.ui.internal.WorkbenchPage.activate(WorkbenchPage.java:585)
	at org.eclipse.ui.internal.WorkbenchPage.makeActive(WorkbenchPage.java:1147)
	at org.eclipse.ui.internal.WorkbenchPage.updateActivePart(WorkbenchPage.java:1127)
	at org.eclipse.ui.internal.WorkbenchPage.handleDeferredEvents(WorkbenchPage.java:1303)
	at org.eclipse.ui.internal.WorkbenchPage.deferUpdates(WorkbenchPage.java:1292)
	at org.eclipse.ui.internal.WorkbenchPage.closeEditors(WorkbenchPage.java:1266)
	at org.eclipse.ui.internal.WorkbenchPage.closeEditor(WorkbenchPage.java:1321)
	at org.eclipse.ui.internal.EditorPane.doHide(EditorPane.java:58)
	at org.eclipse.ui.internal.PartStack.close(PartStack.java:502)
	at org.eclipse.ui.internal.EditorStack.close(EditorStack.java:205)
	at org.eclipse.ui.internal.PartStack$1.close(PartStack.java:109)
	at org.eclipse.ui.internal.presentations.util.TabbedStackPresentation$1.handleEvent(TabbedStackPresentation.java:81)
	at org.eclipse.ui.internal.presentations.util.AbstractTabFolder.fireEvent(AbstractTabFolder.java:267)
	at org.eclipse.ui.internal.presentations.util.AbstractTabFolder.fireEvent(AbstractTabFolder.java:276)
	at org.eclipse.ui.internal.presentations.defaultpresentation.DefaultTabFolder.access$1(DefaultTabFolder.java:1)
	at org.eclipse.ui.internal.presentations.defaultpresentation.DefaultTabFolder$1.closeButtonPressed(DefaultTabFolder.java:67)
	at org.eclipse.ui.internal.presentations.PaneFolder.notifyCloseListeners(PaneFolder.java:580)
	at org.eclipse.ui.internal.presentations.PaneFolder$3.close(PaneFolder.java:187)
	at org.eclipse.swt.custom.CTabFolder.onMouse(CTabFolder.java:2107)
	at org.eclipse.swt.custom.CTabFolder$1.handleEvent(CTabFolder.java:292)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:66)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:927)
	at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3463)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3077)
	at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:1945)
	at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:1909)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:425)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
	at org.eclipse.ui.internal.ide.IDEApplication.run(IDEApplication.java:95)
	at org.eclipse.core.internal.runtime.PlatformActivator$1.run(PlatformActivator.java:78)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:104)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:74)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:348)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:165)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:585)
	at org.eclipse.core.launcher.Main.invokeFramework(Main.java:341)
	at org.eclipse.core.launcher.Main.basicRun(Main.java:285)
	at org.eclipse.core.launcher.Main.run(Main.java:987)
	at org.eclipse.core.launcher.Main.main(Main.java:962)
Comment 1 Markus Keller CLA 2006-12-04 11:22:05 EST
Created attachment 54978 [details]
Fix
Comment 2 Markus Keller CLA 2006-12-04 11:38:17 EST
Released the fix to HEAD. Dani, please review.
Comment 3 Dani Megert CLA 2006-12-11 05:18:19 EST
The fix a workaround. More problems might/will arise in the future due to the workflow change done in AntEditorActionContributor. The menu should be built at the time when init(...) calls contributeToMenu(...), see Javadoc of init(...) for details.

If Ant wants to stay with this hack then it must at least ensure that the menu is built before super.setActiveEditor(part) gets called. This isn't currently the case.

Platform Text will leave the workaround in place since this doesn't harm on our side.
Comment 4 Dani Megert CLA 2006-12-11 05:19:15 EST
Resetting target to 3.3 as this probably won't make it into M4.
Comment 5 Darin Swanson CLA 2006-12-11 10:13:15 EST
I can revisit as time allows but I do not believe this Ant code has changed for almost 2 yrs.
Comment 6 Dani Megert CLA 2006-12-11 10:15:27 EST
Didn't say so. It was probably bad since then and not discovered up to now ;-)
Comment 7 Michael Rennie CLA 2009-05-06 11:53:54 EDT
Not sure if this is even a problem anymore, Markus have you seen this issue recently? Is there a recent version of the ZRH-plugins I can get to try and reproduce?
Comment 8 Markus Keller CLA 2009-05-06 12:32:39 EDT
> Not sure if this is even a problem anymore, Markus have you seen this issue
> recently?

No, I haven't, but that's because our workaround from comment 1 made the NPE go away. I haven't checked the Ant editor, but comment 3 probably still applies.

> Is there a recent version of the ZRH-plugins I can get to try and reproduce?

"ZRH-plugins" just means "all the plug-ins that are maintained in Zurich". I found this problem during our smoke test and committed the workaround to HEAD before the problem even appeared in a build.

To reproduce the original problem, just revert the attached Fix in HEAD, i.e. move

    fQuickAssistMenuEntry= new ActionContributionItem(fQuickAssistAction);

from the constructor of TextEditorActionContributor to after

    if (editMenu != null) {

in TextEditorActionContributor#contributeToMenu(..).
Comment 9 Dani Megert CLA 2009-05-07 05:10:30 EDT
The bug is still present in Ant. Actually there are three issues here:

1. the Javadoc says:

     * The <code>EditorActionBarContributor</code> implementation of this method
     * does nothing. Subclasses may reimplement to add to the menu portion of this
     * contribution.

i.e. clients are allowed to *add* things but not suppress things from your super class. However, in the first call to this method by the editor framework this is not done because of this code:

		if (fOpenDeclarationAction == null) {
			return;
		}
and because fOpenDeclaration is null.

2. Ant itself calls contributeToMenu (a second time) which is not good

3. OpenDeclarationAction.setEditor is broken as the editor site which is stored in the action is not updated


As said in comment 3, future changes in any super class of AntEditorActionContributor might break Ant again.
Comment 10 Eclipse Webmaster CLA 2019-09-06 16:05:16 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.