sonar-golang
sonar-golang copied to clipboard
Overlapping highlighter
Description
The highlighter (Colorizer.java) is producing overlapping highlights that SonarQube cannot handle. I believe this could be due to the highlighting being split across highlightingStringInLine and highlightingKeyWord (and highlightingType which was commented out in the version i checked out, git ee9e6670a35545dbc56457bc5f6d32306b17b569).
I commented out the highlightingKeyWord function in Colorizer.java. Just as an example I had a string that contained the "if" keyword, which I think will be very common. The string was "image.Uniform", obviously that "if" should not be interpreted as a keyword.
137: highlightingStringInLine(s, lineNumber); 138: // highlightingKeyWord(s, lineNumber);
Steps to Reproduce
Create a .go file where variable type contains one of the Golang keywords such as "if", for example image.Uniform.
type Style struct {
fnt *truetype.Font
clr *image.Uniform
}
Log of sonar-scanner related to the plugin
....... ERROR: Error during SonarQube Scanner execution java.lang.IllegalStateException: Cannot register highlighting rule for characters at Range[from [line=29, lineOffset=22] to [line=29, lineOffset=25]] as it overlaps at least one existing rule at org.sonar.api.batch.sensor.highlighting.internal.DefaultHighlighting.checkOverlappingBoudaries(DefaultHighlighting.java:60) at org.sonar.api.batch.sensor.highlighting.internal.DefaultHighlighting.doSave(DefaultHighlighting.java:120) at org.sonar.api.batch.sensor.internal.DefaultStorable.save(DefaultStorable.java:43) at fr.univartois.sonargo.highlighter.Colorizer.colorize(Colorizer.java:48)
Hi, Thanks for your feedback. I have tried to reproduce the problem but I have not this problem because since the version 1.2.7, we had a try catch when saving the coloration. So there is an exception but SonarScanner not stopped. So do you use the 1.2.7+ version ?
Looking in the pom.xml it seems I'm on sonar-golang 1.2.2. Which is strange since I did a "git clone https://github.com/uartois/sonar-golang" today since I didn't see where I could get a prebuilt JAR file.
Where can I get 1.2.7+?
p.s. other version info: INFO: SonarQube Scanner 3.0.3.778 INFO: SonarQube server 6.4.0
Forget last question - now looking at the "Releases" page. Will try again with 1.2.8.
Yes because there are two branch. A master branch with major modification (Actually I develop a v2 with the grammar of go for Highlighting) and maintenance branch for fix bug.
Okay, thanks. I confirm this issue is not in 1.2.8
hi @thibaultfalque I think I've got this error too. here's my logs, using 1.2.8
INFO: Sensor Go Highlighter Sensor [golang]
ERROR: Highlighting problem on save
java.lang.IllegalStateException: Cannot register highlighting rule for characters at Range[from [line=121, lineOffset=17] to [line=121, lineOffset=23]] as it overlaps at least one existing rule
at org.sonar.api.batch.sensor.highlighting.internal.DefaultHighlighting.checkOverlappingBoudaries(DefaultHighlighting.java:60)
at org.sonar.api.batch.sensor.highlighting.internal.DefaultHighlighting.doSave(DefaultHighlighting.java:120)
at org.sonar.api.batch.sensor.internal.DefaultStorable.save(DefaultStorable.java:43)
at fr.univartois.sonargo.highlighter.Colorizer.colorize(Colorizer.java:48)
at fr.univartois.sonargo.highlighter.HighlighterSensor.lambda$1(HighlighterSensor.java:32)
at java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:184)
at java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:175)
at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1374)
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
at java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:151)
at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:174)
at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:418)
at fr.univartois.sonargo.highlighter.HighlighterSensor.execute(HighlighterSensor.java:32)
at org.sonar.scanner.sensor.SensorWrapper.analyse(SensorWrapper.java:53)
at org.sonar.scanner.phases.SensorsExecutor.executeSensor(SensorsExecutor.java:87)
at org.sonar.scanner.phases.SensorsExecutor.execute(SensorsExecutor.java:81)
at org.sonar.scanner.phases.SensorsExecutor.execute(SensorsExecutor.java:67)
at org.sonar.scanner.phases.AbstractPhaseExecutor.execute(AbstractPhaseExecutor.java:75)
at org.sonar.scanner.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:178)
at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:144)
at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:129)
at org.sonar.scanner.scan.ProjectScanContainer.scan(ProjectScanContainer.java:259)
at org.sonar.scanner.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:254)
at org.sonar.scanner.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:243)
at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:144)
at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:129)
at org.sonar.scanner.task.ScanTask.execute(ScanTask.java:47)
at org.sonar.scanner.task.TaskContainer.doAfterStart(TaskContainer.java:86)
at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:144)
at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:129)
at org.sonar.scanner.bootstrap.GlobalContainer.executeTask(GlobalContainer.java:118)
at org.sonar.batch.bootstrapper.Batch.executeTask(Batch.java:117)
at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:63)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:60)
at com.sun.proxy.$Proxy0.execute(Unknown Source)
at org.sonarsource.scanner.api.EmbeddedScanner.doExecute(EmbeddedScanner.java:233)
at org.sonarsource.scanner.api.EmbeddedScanner.runAnalysis(EmbeddedScanner.java:151)
at org.sonarsource.scanner.cli.Main.runAnalysis(Main.java:123)
at org.sonarsource.scanner.cli.Main.execute(Main.java:77)
at org.sonarsource.scanner.cli.Main.main(Main.java:61)
Could you help me?
Hi, Yes the highlighting of the plugin is very simple. So I developed a new version for use the grammar of Go (see issue #20 ). I will search a temporary solution for resolve your problem.
Hi, Please test this version https://github.com/uartois/sonar-golang/tree/v1.2.10-rc1
How could I try it? Pull the source and build by my self? Is that right? Sorry for dumb questions 🙇
Sorry it's not the good link. Download the last release: https://github.com/uartois/sonar-golang/releases.
Just tried the latest release, seems there's no issue 🎉
But the highlight features is disabled by default, is that right?
I tried to set the highlighter via sonar.highlighting=true but the highlight still disabled.
INFO: Sensor Go test JUnit loader sensor [golang] (done) | time=0ms
INFO: Sensor Go Highlighter Sensor [golang]
INFO: highlighting disabled
INFO: Sensor Go Highlighter Sensor [golang] (done) | time=1ms
Could you elaborate on this?
Ok I see. I will correct the problem.
Please retry with the release rc2. Now sonar.highlighting=false disabled highlighting. And the default value is true so the highlighting is activate by default.
Just tried the rc2. The overlapping issue happens again 😭
java.lang.IllegalStateException: Cannot register highlighting rule for characters at Range[from [line=123, lineOffset=17] to [line=123, lineOffset=23]] as it overlaps at least one existing rule
at org.sonar.api.batch.sensor.highlighting.internal.DefaultHighlighting.checkOverlappingBoudaries(DefaultHighlighting.java:60)
at org.sonar.api.batch.sensor.highlighting.internal.DefaultHighlighting.doSave(DefaultHighlighting.java:120)
at org.sonar.api.batch.sensor.internal.DefaultStorable.save(DefaultStorable.java:43)
at fr.univartois.sonargo.highlighter.Colorizer.colorize(Colorizer.java:48)
at fr.univartois.sonargo.highlighter.HighlighterSensor.lambda$execute$1(HighlighterSensor.java:42)
at java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:184)
at java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:175)
at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1374)
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
at java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:151)
at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:174)
at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:418)
at fr.univartois.sonargo.highlighter.HighlighterSensor.execute(HighlighterSensor.java:42)
at org.sonar.scanner.sensor.SensorWrapper.analyse(SensorWrapper.java:53)
at org.sonar.scanner.phases.SensorsExecutor.executeSensor(SensorsExecutor.java:87)
at org.sonar.scanner.phases.SensorsExecutor.execute(SensorsExecutor.java:81)
at org.sonar.scanner.phases.SensorsExecutor.execute(SensorsExecutor.java:67)
at org.sonar.scanner.phases.AbstractPhaseExecutor.execute(AbstractPhaseExecutor.java:75)
at org.sonar.scanner.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:178)
at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:144)
at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:129)
at org.sonar.scanner.scan.ProjectScanContainer.scan(ProjectScanContainer.java:259)
at org.sonar.scanner.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:254)
at org.sonar.scanner.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:243)
at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:144)
at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:129)
at org.sonar.scanner.task.ScanTask.execute(ScanTask.java:47)
at org.sonar.scanner.task.TaskContainer.doAfterStart(TaskContainer.java:86)
at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:144)
at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:129)
at org.sonar.scanner.bootstrap.GlobalContainer.executeTask(GlobalContainer.java:118)
at org.sonar.batch.bootstrapper.Batch.executeTask(Batch.java:117)
at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:63)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:60)
at com.sun.proxy.$Proxy0.execute(Unknown Source)
at org.sonarsource.scanner.api.EmbeddedScanner.doExecute(EmbeddedScanner.java:233)
at org.sonarsource.scanner.api.EmbeddedScanner.runAnalysis(EmbeddedScanner.java:151)
at org.sonarsource.scanner.cli.Main.runAnalysis(Main.java:123)
at org.sonarsource.scanner.cli.Main.execute(Main.java:77)
at org.sonarsource.scanner.cli.Main.main(Main.java:61)
sonar.highlighting is true or false ?
I'm not specify the value of sonar.highlighting, so it must be true
If you have sonar.highlighting at true the highlighting works (it's the default value so you are not obliged to specify the option in sonar-project.properties), you must set the sonar.highlighting to false.
I've just tried again, with sonar.highlighting=true, and the problem still exist.
INFO: Sensor Go Highlighter Sensor [golang]
ERROR: Highlighting problem on save
java.lang.IllegalStateException: Cannot register highlighting rule for characters at Range[from [line=123, lineOffset=17] to [line=123, lineOffset=23]] as it overlaps at least one existing rule
I think I'll disabled this for while if the issue still persist 🙇
Yes it's the idea. The code for highlighting in the plugin is very basic and doesn't work with all possibilities so I will develop a new version (2.0 issue #20) for use the grammar of go for find and highlighting the keyword etc...