Error on first empty lines

  • which versions are you using (SonarQube, Scanner, Plugin, and any relevant extension)
    SonarQube LTS 9.9
    Sonar-scanner 4.8.1

  • what are you trying to achieve
    We use pylint to check Python code with cnes-pylint-extension and sonarjson to give the result to SonarQube.
    When the first line is empty. An error of the scanner is thrown

We already create an issue on the pylint plugin. But the explanation seems to be a problem with SonarQube : sonar-scanner import error when empty line · Issue #7 · omegacen/pylint-sonarjson · GitHub

  • what have you tried so far to achieve this

module ast_python.py :


"""
Classe Database Interrogation
"""

import ast

tree = ast.parse("print('à')")
for node in ast.walk(tree):
    print(node)
    print(node.__dict__)
    print("children: " + str([x for x in ast.iter_child_nodes(node)]) + "\\n")

sonar-projects.properties :

# project metadata
sonar.projectVersion=1.0

# sources
sonar.sources=.


# Pylint report path
sonar.externalIssuesReportPaths=pylint_report.json

The command to reproduce :

python -m venv .venv
source .venv/bin/activate
pip install pip --upgrade
pip install cnes-pylint-extension 
pip install pylint-sonarjson==1.0.5
pylint ast_example.py --rcfile=pylintrc_RNC2015_D --exit-zero --halt-on-invalid-sonar-rules n > pylint_report.json
sonar-scanner 

Error :

INFO: Scanner configuration file: /opt/sonar-scanner/conf/sonar-scanner.properties
INFO: Project root configuration file: /builds/usinelogicielle/private/sandbox/sonar-scanner-error-when-empty-line-on/sonar-project.properties
INFO: SonarScanner 4.8.1.3023
INFO: Java 11.0.20 Alpine (64-bit)
INFO: Linux 3.10.0-1160.95.1.el7.x86_64 amd64
INFO: User cache: /opt/sonar-scanner/.sonar/cache
INFO: Analyzing on SonarQube server 9.9.1.69595
INFO: Default locale: "en_US", source code encoding: "UTF-8" (analysis is platform dependent)
INFO: Load global settings
INFO: Load global settings (done) | time=192ms
INFO: Server id: <SERVER_ID>
INFO: User cache: /opt/sonar-scanner/.sonar/cache
INFO: Load/download plugins
INFO: Load plugins index
INFO: Load plugins index (done) | time=58ms
INFO: Load/download plugins (done) | time=3608ms
INFO: Process project properties
INFO: Process project properties (done) | time=10ms
INFO: Execute project builders
INFO: Execute project builders (done) | time=1ms
INFO: Project key: sonar-scanner-empty-line
INFO: Base dir: /builds/usinelogicielle/private/sandbox/sonar-scanner-error-when-empty-line-on
INFO: Working dir: /builds/usinelogicielle/private/sandbox/sonar-scanner-error-when-empty-line-on/.scannerwork
INFO: Load project settings for component key: 'sonar-scanner-empty-line'
INFO: Load project branches
INFO: Load project branches (done) | time=8ms
INFO: Load branch configuration
INFO: Load branch configuration (done) | time=3ms
INFO: Auto-configuring with CI 'Gitlab CI'
INFO: Load quality profiles
INFO: Load quality profiles (done) | time=188ms
INFO: Load active rules
INFO: Load active rules (done) | time=1734ms
INFO: Load analysis cache
INFO: Load analysis cache (404) | time=8ms
INFO: Branch name: main
INFO: Load project repositories
INFO: Load project repositories (done) | time=19ms
INFO: Indexing files...
INFO: Project configuration:
INFO: 5 files indexed
INFO: 0 files ignored because of scm ignore settings
INFO: Quality profile for json: Sonar way
INFO: Quality profile for py: Sonar way
INFO: ------------- Run sensors on module sonar-scanner-empty-line
INFO: Load metrics repository
INFO: Load metrics repository (done) | time=28ms
INFO: Sensor Import external issues report
INFO: ------------------------------------------------------------------------
INFO: EXECUTION FAILURE
INFO: ------------------------------------------------------------------------
INFO: Total time: 12.046s
INFO: Final Memory: 19M/67M
INFO: ------------------------------------------------------------------------
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:365)
	at org.sonar.api.batch.fs.internal.DefaultInputFile.newRange(DefaultInputFile.java:298)
	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:64)
	at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:88)
	at org.sonar.scanner.sensor.ModuleSensorsExecutor.lambda$execute$1(ModuleSensorsExecutor.java:61)
	at org.sonar.scanner.sensor.ModuleSensorsExecutor.withModuleStrategy(ModuleSensorsExecutor.java:79)
	at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:61)
	at org.sonar.scanner.scan.SpringModuleScanContainer.doAfterStart(SpringModuleScanContainer.java:82)
	at org.sonar.core.platform.SpringComponentContainer.startComponents(SpringComponentContainer.java:188)
	at org.sonar.core.platform.SpringComponentContainer.execute(SpringComponentContainer.java:167)
	at org.sonar.scanner.scan.SpringProjectScanContainer.scan(SpringProjectScanContainer.java:403)
	at org.sonar.scanner.scan.SpringProjectScanContainer.scanRecursively(SpringProjectScanContainer.java:399)
	at org.sonar.scanner.scan.SpringProjectScanContainer.doAfterStart(SpringProjectScanContainer.java:368)
	at org.sonar.core.platform.SpringComponentContainer.startComponents(SpringComponentContainer.java:188)
	at org.sonar.core.platform.SpringComponentContainer.execute(SpringComponentContainer.java:167)
	at org.sonar.scanner.bootstrap.SpringGlobalContainer.doAfterStart(SpringGlobalContainer.java:137)
	at org.sonar.core.platform.SpringComponentContainer.startComponents(SpringComponentContainer.java:188)
	at org.sonar.core.platform.SpringComponentContainer.execute(SpringComponentContainer.java:167)
	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:566)
	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:126)
	at org.sonarsource.scanner.cli.Main.execute(Main.java:81)
	at org.sonarsource.scanner.cli.Main.main(Main.java:62)

Did you reproduce? Can you develop a solution?

Hi there!

Thank you very much for bringing this to us!

I was able to reproduce it and it is a corner case we missed on our side.
I have created a bug ticket which should be tackled in 10.4.

Cheers

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.