Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 363986

Summary: NPE in DefaultFoldingStructureProvider.handleProjectionEnabled
Product: [Modeling] TMF Reporter: Henrik Lindberg <henrik.lindberg>
Component: XtextAssignee: Project Inbox <tmf.xtext-inbox>
Status: RESOLVED DUPLICATE QA Contact:
Severity: normal    
Priority: P3 CC: johan.wannheden
Version: 2.0.1   
Target Milestone: ---   
Hardware: All   
OS: All   
URL: https://github.com/cloudsmith/geppetto/issues/238
Whiteboard: v2.8.4

Description Henrik Lindberg CLA 2011-11-16 19:31:12 EST
Users of Geppetto have reported the NPE below. (The geppetto issue is at https://github.com/cloudsmith/geppetto/issues/238). Have asked for more information about if it is possible to recreate this problem. Also found that the same (or similar issues) have been reported here https://github.com/romainr/PigEditor/issues/7).

Could it be a startup problem?

java.lang.NullPointerException
    at org.eclipse.xtext.ui.editor.folding.DefaultFoldingStructureProvider.handleProjectionEnabled(DefaultFoldingStructureProvider.java:100)
    at org.eclipse.xtext.ui.editor.folding.DefaultFoldingStructureProvider$ProjectionChangeListener.projectionEnabled(DefaultFoldingStructureProvider.java:186)
    at org.eclipse.jface.text.source.projection.ProjectionViewer.fireProjectionEnabled(ProjectionViewer.java:489)
    at org.eclipse.jface.text.source.projection.ProjectionViewer.enableProjection(ProjectionViewer.java:537)
    at org.eclipse.jface.text.source.projection.ProjectionViewer.doOperation(ProjectionViewer.java:1441)
    at org.eclipse.xtext.ui.editor.XtextEditor.installFoldingSupport(XtextEditor.java:439)
    at org.eclipse.xtext.ui.editor.XtextEditor.createPartControl(XtextEditor.java:421)
    at org.eclipse.ui.internal.EditorReference.createPartHelper(EditorReference.java:670)
    at org.eclipse.ui.internal.EditorReference.createPart(EditorReference.java:465)
    at org.eclipse.ui.internal.WorkbenchPartReference.getPart(WorkbenchPartReference.java:595)
    at org.eclipse.ui.internal.EditorReference.getEditor(EditorReference.java:289)
    at org.eclipse.ui.internal.WorkbenchPage.busyOpenEditorBatched(WorkbenchPage.java:2945)
    at org.eclipse.ui.internal.WorkbenchPage.busyOpenEditor(WorkbenchPage.java:2850)
    at org.eclipse.ui.internal.WorkbenchPage.access$11(WorkbenchPage.java:2842)
    at org.eclipse.ui.internal.WorkbenchPage$10.run(WorkbenchPage.java:2793)
    at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:70)
    at org.eclipse.ui.internal.WorkbenchPage.openEditor(WorkbenchPage.java:2789)
    at org.eclipse.ui.internal.WorkbenchPage.openEditor(WorkbenchPage.java:2773)
    at org.eclipse.ui.internal.WorkbenchPage.openEditor(WorkbenchPage.java:2756)
    at org.eclipse.ui.ide.IDE.openEditorOnFileStore(IDE.java:1155)
    at org.eclipse.ui.internal.ide.actions.OpenLocalFileAction.run(OpenLocalFileAction.java:107)
    at org.eclipse.ui.internal.ide.actions.OpenLocalFileAction.run(OpenLocalFileAction.java:76)
    at org.eclipse.ui.internal.PluginAction.runWithEvent(PluginAction.java:251)
    at org.eclipse.ui.internal.WWinPluginAction.runWithEvent(WWinPluginAction.java:229)
    at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:584)
    at org.eclipse.jface.action.ActionContributionItem.access$2(ActionContributionItem.java:501)
    at org.eclipse.jface.action.ActionContributionItem$5.handleEvent(ActionContributionItem.java:411)
    at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
    at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4128)
    at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1457)
    at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1480)
    at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1465)
    at org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java:1270)
    at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3974)
    at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3613)
    at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2696)
    at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2660)
    at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2494)
    at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:674)
    at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
    at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:667)
    at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
    at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:123)
    at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:344)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
    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:597)
    at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:622)
    at org.eclipse.equinox.launcher.Main.basicRun(Main.java:577)
    at org.eclipse.equinox.launcher.Main.run(Main.java:1410)
Comment 1 Henrik Lindberg CLA 2011-11-17 10:11:14 EST
Further investigation revealed that this was caused by using "open file" and opening a file that was not in the workspace.

Rather than crashing, I would like to intervene and pop a dialog "opening files external to the workspace is not supported, please use linked files" (or some such). Where is a good place to do that?
Comment 2 Henrik Lindberg CLA 2011-11-17 17:02:08 EST
The exception is from:
protected void handleProjectionEnabled() {
		handleProjectionDisabled();
		if (isInstalled()) {
			initialize();
			editor.getDocument().addModelListener(this);  // <--- NULL DOCUMENT
		}
	}

where editor.getDocument() returns null, because XtextDocumentUtil.get(Object) receives a context for an XtextSourceViewer that returns null on getDocument().

Also See https://bugs.eclipse.org/bugs/show_bug.cgi?id=289212 (support opening external files).

I do however just a way to *not open editor with NPE*.
Comment 3 Henrik Lindberg CLA 2011-11-17 18:04:52 EST
I experimented, and protecting the DefaultFoldingStructureProvider.handleProjectionEnabled from the NPE, just moves the problem elsewhere. The next place is HighlightingReconciler.refresh:243 where editor.getDocument() is called without a check for null.

If that is also fixed, the problem moves to StyledCellLabelProvider, where an assert is made like so:
    Assert.isTrue(this.viewer == null && this.column == null, "Label provider instance already in use");

Result is that editor opens up with an ugly "An error has occurred - see log for more details" with the message from the assert being logged.

Trying to protect against the null document seems to be the wrong approach.
Comment 4 Johan Wannheden CLA 2011-11-29 05:37:21 EST
I'm facing a similar problem when trying to open a file outside the workspace (using an implementation of LanguageSpecificURIEditorOpener). The exceptions raised are those descriped in http://stackoverflow.com/questions/8239458/cannot-open-workspace-external-file-in-xtext-based-plugin.
Comment 5 Karsten Thoms CLA 2017-07-11 17:27:18 EDT
fixed in 2.8.4

*** This bug has been marked as a duplicate of bug 470557 ***