-
Notifications
You must be signed in to change notification settings - Fork 4
sonar-scanner import error when empty line #7
Comments
Hang on, when the end column is zero it doesn't get added to the JSON output: pylint-sonarjson/src/pylint_sonarjson/sonarjson_reporter.py Lines 56 to 57 in 41c81c3
If msg.end_column is 0 , the conditional on line 56 does not evaluate to true (which is not correct in other circumstances; that logic should probably be changed).
So I'm a little puzzled how SonarQube can spit out the above error on empty lines. Can you provide the JSON output of pylint-sonarjson and the code on which it is generated? |
Sorry for the late answer. Here the incriminated code :
Here the configuratiion file :
Here the commands :
Here the output :
The 3 issues start at line 1 but line 1 is empty. So sonar-scanner crash searching line code |
Thanks for the code, I can reproduce your JSON output. To be honest, this looks like a issue in SonarQube to me. If you omit the endColumn but provide the startColumn, SonarQube will set the end column equal to the last column of the line (ExternalIssueImporter.java#L126). But then later on SonarQube will check for a non-zero length text interval (DefaultInputFile.java#L365), which in your case is zero, and then it raises the This does not happen when the startColumn is omitted, because SonarQube will then not set the endColumn equal to the last column of the line (ExternalIssueImporter.java#L121). There's no way to fix this properly in the pylint plugin. Simply omitting the startColumn when it is equal to So I'm afraid I'll have to ask to report this upstream to SonarQube. If they respond with something like "you have to always provide startColumn and endColumn together" then I'm happy to make the corresponding changes here. If they respond with improving their code, even better. I have some final questions for you though: why does the module in your example start with an empty line? And why does |
Hi @teake , We created a post on SonarQube Forum. You can close the issue |
Hi @teake,
I'm working with @usinelogicielle team.
We detect an error using your plugin in a specific case.
We have rules in our SonarQube to add specific comment on the first lines of a module.
If an issue is detected on empty line sonar-scanner shown an error because the first and end pointer is the same :
ERROR: Error during SonarScanner execution java.lang.IllegalArgumentException: Start pointer [line=1, lineOffset=0] should be before end pointer [line=1, lineOffset=0] at org.sonar.api.utils.Preconditions.checkArgument(Preconditions.java:43) at org.sonar.api.batch.fs.internal.DefaultInputFile.newRangeValidPointers(DefaultInputFile.java:348) at org.sonar.api.batch.fs.internal.DefaultInputFile.newRange(DefaultInputFile.java:281) at org.sonar.scanner.externalissue.ExternalIssueImporter.fillLocation(ExternalIssueImporter.java:133) at org.sonar.scanner.externalissue.ExternalIssueImporter.importIssue(ExternalIssueImporter.java:81) at org.sonar.scanner.externalissue.ExternalIssueImporter.execute(ExternalIssueImporter.java:57) at org.sonar.scanner.externalissue.ExternalIssuesImportSensor.execute(ExternalIssuesImportSensor.java:74) 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:137) at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:123) at org.sonar.scanner.scan.ProjectScanContainer.scan(ProjectScanContainer.java:392) at org.sonar.scanner.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:388) at org.sonar.scanner.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:357) at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:137) at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:123) at org.sonar.scanner.bootstrap.GlobalContainer.doAfterStart(GlobalContainer.java:150) at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:137) at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:123) 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(NativeMethodAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:567) 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)
Reading the SonarQube documentation https://docs.sonarqube.org/8.9/analysis/generic-issue/
startColumn field is optionnal. So on empty line it shouldn't be fullfilled.
I tested it and it works. I'll propose a solution
The text was updated successfully, but these errors were encountered: