sbaudoin/sonar-shellcheck

Issue with specials caracters 'FF' (FORM FEED), 'CR' (CARIAGE RETURN) in shell scripts

Closed this issue · 4 comments

Hi there,

I have an issue with the sonar-shellcheck plugin.

I have some specials caracters 'FF' (FORM FEED), 'CR' (CARIAGE RETURN) in shell scripts, and it doesn't work with the sonar-shellcheck plugin :

ERROR: Error during SonarScanner execution
java.lang.IllegalArgumentException: Unable to highlight file [...]
        at org.sonar.api.batch.sensor.highlighting.internal.DefaultHighlighting.highlight(DefaultHighlighting.java:97)
        at org.sonar.api.batch.sensor.highlighting.internal.DefaultHighlighting.highlight(DefaultHighlighting.java:37)
        at com.github.sbaudoin.sonar.plugins.shellcheck.highlighting.HighlightingData.highlight(HighlightingData.java:58)
        at com.github.sbaudoin.sonar.plugins.shellcheck.rules.ShellCheckSensor.saveSyntaxHighlighting(ShellCheckSensor.java:298)
        at com.github.sbaudoin.sonar.plugins.shellcheck.rules.ShellCheckSensor.execute(ShellCheckSensor.java:139)
        at org.sonar.scanner.sensor.AbstractSensorWrapper.analyse(AbstractSensorWrapper.java:48)
        at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:85)
        at org.sonar.scanner.sensor.ModuleSensorsExecutor.lambda$execute$1(ModuleSensorsExecutor.java:59)
        at org.sonar.scanner.sensor.ModuleSensorsExecutor.withModuleStrategy(ModuleSensorsExecutor.java:77)
        at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:59)
        at org.sonar.scanner.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:82)
        at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:136)
        at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:122)
        at org.sonar.scanner.scan.ProjectScanContainer.scan(ProjectScanContainer.java:386)
        at org.sonar.scanner.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:382)
        at org.sonar.scanner.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:351)
        at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:136)
        at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:122)
        at org.sonar.scanner.bootstrap.GlobalContainer.doAfterStart(GlobalContainer.java:141)
        at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:136)
        at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:122)
        at org.sonar.batch.bootstrapper.Batch.doExecute(Batch.java:72)
        at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:66)
        at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:46)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.base/java.lang.reflect.Method.invoke(Unknown Source)
        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:189)
        at org.sonarsource.scanner.api.EmbeddedScanner.execute(EmbeddedScanner.java:138)
        at org.sonarsource.scanner.cli.Main.execute(Main.java:112)
        at org.sonarsource.scanner.cli.Main.execute(Main.java:75)
        at org.sonarsource.scanner.cli.Main.main(Main.java:61)
Caused by: java.lang.IllegalArgumentException: 26 is not a valid line offset for pointer. File [...] has 23 character(s) at line 98
        at org.sonar.api.utils.Preconditions.checkArgument(Preconditions.java:43)
        at org.sonar.api.batch.fs.internal.DefaultInputFile.checkValid(DefaultInputFile.java:339)
        at org.sonar.api.batch.fs.internal.DefaultInputFile.newPointer(DefaultInputFile.java:272)
        at org.sonar.api.batch.fs.internal.DefaultInputFile.newRange(DefaultInputFile.java:288)
        at org.sonar.api.batch.sensor.highlighting.internal.DefaultHighlighting.highlight(DefaultHighlighting.java:95)
        ... 34 more

Can you fix this issue ?

Hello,

@FrancoisXavierNoe I cannot reproduce the issue: can you ZIP and send a short, sample file that contains such a character sequence that I can use to debug, please?

Thx

@FrancoisXavierNoe Never mind: I managed to reproduce the issue. I fix it.

Hello

@sbaudoin It is really a great news if you fix this issue !

Thanks a lot !

You will find below two examples if needed (maybe usefull to validate the PR)
examples.zip

When do you think that this fix could be available ?

Thanks again

Hello. I don't know yet. It should be available by the end of the week, depending on the time I need to review the rules of the plugin. BTW, the way I fixed is not totally satisfactory: the CR character was not correctly treated as a line break character so I fixed that but for the other characters I cannot but handle the IllegalArgumentException that can be raised when highlighting the code. As a consequence, the plugin will pass, showing a warning with the stacktrace you had, the issues will be reported, but the code will not be highlighted in SQ. I tried in different ways but so far that's all I can actually achieve.