org.eclipse.jface.text.BadLocationException in Sonar in combination with Save actions for the formatter and undo

I’m getting on a regular basis the following exception.

How to reproduce:
1.) Enable save action especially the Formatter
2.) Write a long line of code, longer than the formatter will allow
3.) Save -> Formatter will break the line into tow
4.) Press Ctrl+Z to undo the formatter action

-> Exception

failed to get text range content of resource /org.eclipse.core.resources/src/org/eclipse/core/internal/resources/Project.java
org.eclipse.jface.text.BadLocationException
	at org.eclipse.jface.text.AbstractDocument.get(AbstractDocument.java:968)
	at org.eclipse.core.internal.filebuffers.SynchronizableDocument.get(SynchronizableDocument.java:130)
	at org.sonarlint.eclipse.core.internal.jobs.AbstractAnalyzeProjectJob.readTextRangeContent(AbstractAnalyzeProjectJob.java:349)
	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)

Hi Lars,

Thanks for reporting this. I spent some time on it but I was not able to reproduce. There is probably something more in the loop. Can you just precise:

  • the version of SonarLint you are using (I’m assuming 4.1.0.201901311043)
  • are you using connected mode to bind your project to a specific SonarQube server or SonarCloud?
  • is the analysis of the file slow (it may increase the likelihood of a race condition)?

It might be interesting to share the SonarLint verbose console output if you can reproduce consistently the issue.

Thanks

Hi Julian,

1.) SonarSource SonarLint for Eclipse 4.1.0.201901311043 org.sonarlint.eclipse.feature
2.) No
3.) The workspace is big so everything is slow.

As for the verbose output: Do you have a trace available? Or where do I see the output?

Please open the SonarLint console (in the console view), and use the toolbar to enable verbose and analysis logs:
image
Clear the console, reproduce the bug, then please collect all logs.

Also, do you have any issue reported on the line you are editing (prior editing?)

I now see that the file is excluded:

File ‘src/org/eclipse/core/internal/resources/Project.java’ excluded by ‘JavaProjectConfiguratorExtension’

Why is that?

If you are in the middle of an edition when you save, the code may be unparseable/have compilation errors, so we are trying to save time by skipping analysis (our analyzers only accept well-formed code).

If the analysis is skipped, it should not lead to the error you mentioned earlier. Are you talking about the same file/problem?

IIRC this was the file for which Sonar gave the exeception. Currently I’m unable to reproduce but once I see the error again I post the log.

Closing this thread due to lack of activity.

Feel free to open a new thread if you still have an issue/question.