SonarLint Eclipse 4.1.0.201901311043
- started Eclipse, which in turn automatically starts Sonarlint scanning
- ran git pull, and that finished immediately before Sonarlint was done with the analysis
- the git pull removed quite some file content which had been analyzed by Sonarlint before
- when Sonarlint wanted to place markers, some of those were behind the end of the (now shorter) file.
Example exception from the Sonarlint console:
failed to compute line offsets for start, end = 1057, 1057 org.eclipse.jface.text.BadLocationException at org.eclipse.jface.text.ListLineTracker.getLineOffset(ListLineTracker.java:197) at org.eclipse.jface.text.AbstractLineTracker.getLineOffset(AbstractLineTracker.java:160) at org.eclipse.jface.text.AbstractDocument.getLineOffset(AbstractDocument.java:876) at org.eclipse.core.internal.filebuffers.SynchronizableDocument.getLineOffset(SynchronizableDocument.java:323) at org.sonarlint.eclipse.core.internal.markers.MarkerUtils.convertToGlobalOffset(MarkerUtils.java:131) at org.sonarlint.eclipse.core.internal.markers.MarkerUtils.getPosition(MarkerUtils.java:110) at org.sonarlint.eclipse.core.internal.markers.MarkerUtils.getPosition(MarkerUtils.java:85) at org.sonarlint.eclipse.core.internal.jobs.AbstractAnalyzeProjectJob.readTextRangeContent(AbstractAnalyzeProjectJob.java:346) at org.sonarlint.eclipse.core.internal.jobs.AbstractAnalyzeProjectJob.transform(AbstractAnalyzeProjectJob.java:339) at org.sonarlint.eclipse.core.internal.jobs.AbstractAnalyzeProjectJob.lambda$14(AbstractAnalyzeProjectJob.java:314) at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195) at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1654) at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484) at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474) at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:913) at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:578) at org.sonarlint.eclipse.core.internal.jobs.AbstractAnalyzeProjectJob.trackIssues(AbstractAnalyzeProjectJob.java:314) at org.sonarlint.eclipse.core.internal.jobs.AbstractAnalyzeProjectJob.updateMarkers(AbstractAnalyzeProjectJob.java:300) at org.sonarlint.eclipse.core.internal.jobs.AbstractAnalyzeProjectJob.runAnalysisAndUpdateMarkers(AbstractAnalyzeProjectJob.java:207) at org.sonarlint.eclipse.core.internal.jobs.AbstractAnalyzeProjectJob.doRun(AbstractAnalyzeProjectJob.java:167) at org.sonarlint.eclipse.core.internal.jobs.AbstractSonarProjectJob.runInWorkspace(AbstractSonarProjectJob.java:44) at org.eclipse.core.internal.resources.InternalWorkspaceJob.run(InternalWorkspaceJob.java:42) at org.eclipse.core.internal.jobs.Worker.run(Worker.java:63)
This is basically impossible to reproduce on purpose, since the timing of the scan and the time of the file change probably must overlap in a very certain pattern. Nevertheless you may want to wrap your marker creation code by a try-catch, or even re-start the analysis for that file when getting this specific exception.