NPE due to file opened from Git history

Using latest Eclipse and latest Sonarlint, I get an NPE if I open a .adoc file from the Git History view. To reproduce:

1.) Select an commit which modified a file
2.) Select a file, right mouse click and select Open previous version.
3.) Click into the editor and you get the NPE from below.

java.lang.NullPointerException: Cannot invoke "org.eclipse.jface.text.source.IAnnotationModel.getAnnotationIterator()" because "annotationModel" is null
	at org.sonarlint.eclipse.ui.internal.flowlocations.SonarLintFlowAnnotator.existingFlowAnnotations(SonarLintFlowAnnotator.java:231)
	at org.sonarlint.eclipse.ui.internal.flowlocations.SonarLintFlowAnnotator.updateFlowAnnotations(SonarLintFlowAnnotator.java:176)
	at org.sonarlint.eclipse.ui.internal.flowlocations.SonarLintFlowAnnotator.<init>(SonarLintFlowAnnotator.java:145)
	at org.sonarlint.eclipse.ui.internal.flowlocations.SonarLintFlowAnnotator$1.partActivated(SonarLintFlowAnnotator.java:66)
	at org.eclipse.ui.internal.WorkbenchPage$4.run(WorkbenchPage.java:4903)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:45)
	at org.eclipse.ui.internal.WorkbenchPage.firePartActivated(WorkbenchPage.java:4900)
	at org.eclipse.ui.internal.WorkbenchPage$E4PartListener.partActivated(WorkbenchPage.java:219)
	at org.eclipse.e4.ui.internal.workbench.PartServiceImpl$2.run(PartServiceImpl.java:249)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:45)
	at org.eclipse.e4.ui.internal.workbench.PartServiceImpl.firePartActivated(PartServiceImpl.java:246)
	at org.eclipse.e4.ui.internal.workbench.PartServiceImpl.activate(PartServiceImpl.java:770)
	at org.eclipse.e4.ui.internal.workbench.PartServiceImpl.activate(PartServiceImpl.java:679)
	at org.eclipse.e4.ui.internal.workbench.swt.AbstractPartRenderer.activate(AbstractPartRenderer.java:97)
	at org.eclipse.e4.ui.workbench.renderers.swt.StackRenderer.lambda$4(StackRenderer.java:979)
	at org.eclipse.swt.events.SelectionListener$1.widgetSelected(SelectionListener.java:84)
	at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:252)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:89)
	at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4209)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1037)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1061)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1046)
	at org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java:760)
	at org.eclipse.swt.custom.CTabFolder.setSelection(CTabFolder.java:3241)
	at org.eclipse.swt.custom.CTabFolder.onMouse(CTabFolder.java:1879)
	at org.eclipse.swt.custom.CTabFolder.lambda$0(CTabFolder.java:330)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:89)
	at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4209)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1037)
	at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4026)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3626)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$5.run(PartRenderingEngine.java:1157)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:338)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1046)
	at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:155)
	at org.eclipse.ui.internal.Workbench.lambda$3(Workbench.java:644)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:338)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:551)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:156)
	at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:152)
	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:203)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:134)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:401)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:255)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:564)
	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:653)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:590)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1461)

Hi @vogella

I think I have enough information to fix the problem, but just to be 100% sure, can you verify my assumption: I don’t think the issue is related to opening from Git History. You will probably have the same issue when opening directly the .adoc file, right?

BTW can you tell me the name of the editor you use to open .adoc files, and from which plugin it comes from?

Anyway thanks for reporting the issue!

Edit: ticket created: https://jira.sonarsource.com/browse/SLE-400

Hi Julian,

no if I open the .adoc file directly from the project explorer I do not see this issue. I use https://marketplace.eclipse.org/content/asciidoctor-editor for editing adoc files.

OK, I will try to reproduce to understand why sometimes the editor has no annotation model.

In the meantime, if this is too annoying for you, feel free to use this artifact with a defensive null check:
https://repox.jfrog.io/repox/sonarsource/org/sonarsource/sonarlint/eclipse/org.sonarlint.eclipse.site/5.6.0.25022/org.sonarlint.eclipse.site-5.6.0.25022.zip

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.