Bug 141013 - Open editor via doubleclick sometimes give NPE in AbstractTextEditor.getAction
Summary: Open editor via doubleclick sometimes give NPE in AbstractTextEditor.getAction
Status: CLOSED FIXED
Alias: None
Product: WTP Source Editing
Classification: WebTools
Component: wst.sse (show other bugs)
Version: 1.5   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 1.5.1 M151   Edit
Assignee: Amy Wu CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 148466 150479 150708 150935 152500 152509 152942 156092 159354 (view as bug list)
Depends on:
Blocks:
 
Reported: 2006-05-10 08:57 EDT by Max Rydahl Andersen CLA
Modified: 2007-04-03 11:24 EDT (History)
8 users (show)

See Also:


Attachments
org.eclipse.wst.xml.ui (1.75 KB, patch)
2006-07-21 18:30 EDT, Amy Wu CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Max Rydahl Andersen CLA 2006-05-10 08:57:51 EDT
I've now bumped into this one more than a few times so i'm pretty sure it is a recurring eclipse or WTP bug.

Sometimes when I double click on an xml file (and there is no real pattern on what type of xml) then I get a "Unable to create this part...." in the editor instead of the real editor. 

If I close this errored editor and do the same action (double click) it works fine.

The stacktrace is as follows:

java.lang.NullPointerException
	at org.eclipse.ui.texteditor.AbstractTextEditor.getAction(AbstractTextEditor.java:4023)
	at org.eclipse.wst.xml.ui.internal.tabletree.XMLTableTreeActionBarContributor.getAction(XMLTableTreeActionBarContributor.java:210)
	at org.eclipse.wst.xml.ui.internal.tabletree.XMLTableTreeActionBarContributor.setActiveEditor(XMLTableTreeActionBarContributor.java:198)
	at org.eclipse.wst.xml.ui.internal.tabletree.XMLMultiPageEditorActionBarContributor.activateSourcePage(XMLMultiPageEditorActionBarContributor.java:54)
	at org.eclipse.wst.xml.ui.internal.tabletree.SourceEditorActionBarContributor.setActivePage(SourceEditorActionBarContributor.java:168)
	at org.eclipse.ui.part.MultiPageEditorPart.pageChange(MultiPageEditorPart.java:588)
	at org.eclipse.wst.xml.ui.internal.tabletree.XMLMultiPageEditorPart.pageChange(XMLMultiPageEditorPart.java:739)
	at org.eclipse.ui.part.MultiPageEditorPart.setActivePage(MultiPageEditorPart.java:689)
	at org.eclipse.wst.xml.ui.internal.tabletree.XMLMultiPageEditorPart.createPages(XMLMultiPageEditorPart.java:509)
	at org.eclipse.ui.part.MultiPageEditorPart.createPartControl(MultiPageEditorPart.java:275)
	at org.eclipse.ui.internal.EditorReference.createPartHelper(EditorReference.java:596)
	at org.eclipse.ui.internal.EditorReference.createPart(EditorReference.java:372)
	at org.eclipse.ui.internal.WorkbenchPartReference.getPart(WorkbenchPartReference.java:566)
	at org.eclipse.ui.internal.EditorReference.getEditor(EditorReference.java:214)
	at org.eclipse.ui.internal.WorkbenchPage.busyOpenEditorBatched(WorkbenchPage.java:2537)
	at org.eclipse.ui.internal.WorkbenchPage.busyOpenEditor(WorkbenchPage.java:2470)
	at org.eclipse.ui.internal.WorkbenchPage.access$10(WorkbenchPage.java:2462)
	at org.eclipse.ui.internal.WorkbenchPage$9.run(WorkbenchPage.java:2447)
	at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:67)
	at org.eclipse.ui.internal.WorkbenchPage.openEditor(WorkbenchPage.java:2442)
	at org.eclipse.ui.internal.WorkbenchPage.openEditor(WorkbenchPage.java:2427)
	at org.eclipse.ui.ide.IDE.openEditor(IDE.java:388)
	at org.eclipse.ui.ide.IDE.openEditor(IDE.java:350)
	at org.eclipse.ui.ide.IDE.openEditor(IDE.java:776)
	at org.eclipse.ui.views.markers.internal.ActionOpenMarker.run(ActionOpenMarker.java:86)
	at org.eclipse.ui.views.markers.internal.MarkerView.handleOpenEvent(MarkerView.java:1052)
	at org.eclipse.ui.views.markers.internal.TableView$2.open(TableView.java:176)
	at org.eclipse.jface.viewers.StructuredViewer$2.run(StructuredViewer.java:811)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:37)
	at org.eclipse.core.runtime.Platform.run(Platform.java:843)
	at org.eclipse.ui.internal.JFaceUtil$1.run(JFaceUtil.java:44)
	at org.eclipse.jface.util.SafeRunnable.run(SafeRunnable.java:149)
	at org.eclipse.jface.viewers.StructuredViewer.fireOpen(StructuredViewer.java:809)
	at org.eclipse.jface.viewers.StructuredViewer.handleOpen(StructuredViewer.java:1063)
	at org.eclipse.jface.viewers.StructuredViewer$6.handleOpen(StructuredViewer.java:1162)
	at org.eclipse.jface.util.OpenStrategy.fireOpenEvent(OpenStrategy.java:249)
	at org.eclipse.jface.util.OpenStrategy.access$2(OpenStrategy.java:243)
	at org.eclipse.jface.util.OpenStrategy$1.handleEvent(OpenStrategy.java:283)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:66)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:925)
	at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3348)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2968)
	at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:1914)
Comment 1 David Williams CLA 2006-05-13 20:14:23 EDT
Amy, I think I've seen some base bugs on this too ... if you want to scan those. 

This might also be caused by some sort of "leak", where some editor was disposed (hence, fActions at line 4023 is null) but is being "opened again". 
Comment 2 coolman5453 CLA 2006-06-23 13:47:15 EDT
I've been getting this error since I started trying the 3.2 release candidates.  I just got it twice on RC7 in the past 5 minutes...the exact same error message, exact same line number.

But, if you close the error message, then double click on the XML again, it works.
Comment 3 Amy Wu CLA 2006-06-26 14:39:52 EDT
I have not been able to recreate this in my copy of WTP 1.5 RC6.  Did you already have several xml editors open?  Did you just close this editor and then immediately tried to open it again?  Were you opening a lot of editors really quickly? Do you open the xml editor with the design page open first or the source page?

Like David pointed out, the exception is complaining of fActions being null, and the only time it is null is when the editor is disposed.  So something must be disposing of it, then trying to reopen.  One possibility is in StructuredTextEditor#doSetInput().  If a CoreException is caught, the editor is disposed, then throws a new CoreException.  I wonder if we really need to call dispose() there.
Comment 4 Amy Wu CLA 2006-07-17 17:27:21 EDT
*** Bug 148466 has been marked as a duplicate of this bug. ***
Comment 5 Amy Wu CLA 2006-07-18 12:12:34 EDT
*** Bug 150935 has been marked as a duplicate of this bug. ***
Comment 6 Amy Wu CLA 2006-07-18 12:15:45 EDT
*** Bug 150708 has been marked as a duplicate of this bug. ***
Comment 7 Amy Wu CLA 2006-07-18 12:18:41 EDT
*** Bug 150479 has been marked as a duplicate of this bug. ***
Comment 8 Darryl Miles CLA 2006-07-18 13:46:13 EDT
Just to help here.  I was using double click in the Package Explorer to open files and I did the following sequence to get hit with it.  I had maybe another 4 to 6 editors open, but IIRC none were for XML files those editors were JSP and Java.  My sequence today went something like:

Double click on WEB-INF/lib/servlets.xml
Whoops not the file I'm looking for, so very soon (< 1.5 seconds) I click the X in the editor tab to close it.

Double click on WEB-INF/lib/servlet-mappings.xml
Again very soon I click the X in the editor tab to close it.

Double click on WEB-INF/lib/filters.xml
Again very soon I click the X in the editor tab to close it.

Double click on WEB-INF/lib/filter-mappings.xml
Ah.. now I got the error!

When I X to close, it closed the editors tab and I could just re-open it like normal by double cliking again, this time it worked.

Comment 9 Amy Wu CLA 2006-07-21 18:25:58 EDT
Thanks everyone for their scenaros.  I was finally able to reproduce this problem, and I found a completely reproducible scenario:
1. open xml editor, A
2. open a non-xml editor
3. open another xml editor, B
4. close xml editor B
5. reopen xml editor B
6. Exception occurs

The problem appears to be with the action bar contributor.  Basically, MultiPageActionBarContributor.setActivePage is called before MultiPageActionBarContributor.setActiveEditor.  setActivePage utilizes what it thinks is the current multipageeditor when really, the multipageeditor variable is stale (it is the last editor which may have been disposed) when setActivePage is called before setActiveEditor (which is where multipageeditor is set)

I opened bug 151488 on the base because the code that calls setActivePage & setActiveEditor is basically in their code.  But I do have a workaround in the meantime to call setActiveEditor before setActivePage is first called when the editor is loaded.

Add the following in XMLMultiPageEditorPart.createPages:
// set the active editor in the action bar contributor first
// before setactivepage calls action bar contributor's
// setactivepage
IEditorActionBarContributor contributor = getEditorSite().getActionBarContributor();
if (contributor != null && contributor instanceof MultiPageEditorActionBarContributor) {
	((MultiPageEditorActionBarContributor) contributor).setActiveEditor(this);
}
Comment 10 Amy Wu CLA 2006-07-21 18:30:43 EDT
Created attachment 46668 [details]
org.eclipse.wst.xml.ui
Comment 11 Amy Wu CLA 2006-07-26 12:31:57 EDT
Fix has been released to 1.5.1 & head.
Comment 12 Amy Wu CLA 2006-08-01 15:53:00 EDT
*** Bug 152500 has been marked as a duplicate of this bug. ***
Comment 13 Paul Webster CLA 2006-08-01 21:35:11 EDT
*** Bug 152509 has been marked as a duplicate of this bug. ***
Comment 14 Amy Wu CLA 2006-08-07 10:22:46 EDT
*** Bug 152942 has been marked as a duplicate of this bug. ***
Comment 15 Amy Wu CLA 2006-09-05 12:00:52 EDT
*** Bug 156092 has been marked as a duplicate of this bug. ***
Comment 16 Victor Toni CLA 2006-10-10 18:44:28 EDT
*** Bug 159354 has been marked as a duplicate of this bug. ***
Comment 17 John Lanuti CLA 2007-04-03 11:24:16 EDT
Closing as resolved since 1.5.1.  If this bug should not be closed, please reopen.