Error: Line number must be strictly possitive:0

ERROR: Error during SonarQube Scanner execution
java.lang.IllegalStateException: Line number must be strictly positive: 0

  • SonarQube 7.9.4 LTS Community Edition
  • SonarQube Scanner 2.9.0.670
  • We are trying to run the build via Jenkins. But the build is getting failure with below error. Please assist on this.

ERROR: Error during SonarQube Scanner execution
java.lang.IllegalStateException: Line number must be strictly positive: 0
at org.sonar.api.internal.google.common.base.Preconditions.checkState(Preconditions.java:197)
at org.sonar.api.batch.sensor.coverage.internal.DefaultCoverage.validateLine(DefaultCoverage.java:94)
at org.sonar.api.batch.sensor.coverage.internal.DefaultCoverage.lineHits(DefaultCoverage.java:81)
at org.sonar.plugins.cobertura.CoberturaReportParser.collectFileData(CoberturaReportParser.java:117)
at org.sonar.plugins.cobertura.CoberturaReportParser.collectFileMeasures(CoberturaReportParser.java:98)
at org.sonar.plugins.cobertura.CoberturaReportParser.collectPackageMeasures(CoberturaReportParser.java:87)
at org.sonar.plugins.cobertura.CoberturaReportParser.parse(CoberturaReportParser.java:67)
at org.sonar.plugins.cobertura.CoberturaReportParser.parseReport(CoberturaReportParser.java:58)
at org.sonar.plugins.cobertura.CoberturaSensor.parseReport(CoberturaSensor.java:72)
at org.sonar.plugins.cobertura.CoberturaSensor.execute(CoberturaSensor.java:66)
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:400)
at org.sonar.scanner.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:395)
at org.sonar.scanner.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:358)
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:73)
at org.sonar.batch.bootstrapper.Batch.executeTask(Batch.java:99)
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)
ERROR:
ERROR: Re-run SonarQube Scanner using the -X switch to enable full debug logging.
WARN: Unable to locate ‘report-task.txt’ in the workspace. Did the SonarScanner succeed?
ERROR: SonarQube scanner exited with non-zero code: 1
Finished: FAILURE

Hello @UNagaTh,

First of all you’re using a very old version of the SonarQube scanner (version 2.9). We’re now at 4.4, very far ahead. I would therefore request you to upgrade to Scanner 4.4 before we investigate your issue in depth.

Second, it seems that the problem comes from the Cobertura plugin. This plugin is a 3rd party community plugin and is neither maintained nor supported by SonarSource. You may want to post your problem on the Cobertura plugin issue tracker.

One hint: From the error it could well be that the root cause is an incorrect Cobertura report. Indeed, coverage data should refer to line numbers that in essence must be strictly positive. If the report contains coverage data for a line 0, it’s kind of normal that the Cobertura plugin fails on it.

That’s all I’ll be able to say on that thread. Good luck!

Thank you for the reply. I will check and make the changes as you suggested and post the results here.

Hi @OlivierK,

We tried with the options you provided. We are able to get the coverage locally. However, we are getting the same error when we trigger with Sonar Scanner in SonarQube.

I will attach the build logs here. Please assist me.

Thanks

Hello,

Can you be a bit more specific on what you did and what results you got ?

I will attach the build logs here. Please assist me.

Well, send the logs and I’ll see if I can do something. No promise if that’s a Cobertura problem.

We have updated the sonar scanner version to 4.4 and yes, we are using Cobertura plugin and we getting coverage in local. But not in SonarQube.

Here are logs:
INFO: Scanner configuration file: /jenkins/.jenkins/tools/hudson.plugins.sonar.SonarRunnerInstallation/pearsonsonarscanner/conf/sonar-scanner.properties
INFO: Project root configuration file: NONE
INFO: SonarScanner 4.3.0.2102
INFO: Java 1.8.0_112 Oracle Corporation (64-bit)
INFO: Linux 3.10.0-229.20.1.el7.x86_64 amd64
INFO: User cache: /jenkins/.sonar/cache
INFO: Scanner configuration file: /jenkins/.jenkins/tools/hudson.plugins.sonar.SonarRunnerInstallation/pearsonsonarscanner/conf/sonar-scanner.properties
INFO: Project root configuration file: NONE
INFO: Analyzing on SonarQube server 7.9.4
INFO: Default locale: “en_US”, source code encoding: “UTF-8”
WARN: SonarScanner will require Java 11 to run starting in SonarQube 8.x
INFO: Load global settings
INFO: Load global settings (done) | time=1907ms
INFO: Server id: 14458AED-1aa489f766049a6
INFO: User cache: /jenkins/.sonar/cache
INFO: Load/download plugins
INFO: Load plugins index
INFO: Load plugins index (done) | time=1553ms
INFO: Plugin [l10nja] defines ‘l10nen’ as base plugin. This metadata can be removed from manifest of l10n plugins since version 5.2.
INFO: Load/download plugins (done) | time=1614ms
WARN: API compatibility mode is no longer supported. In case of error, plugin Japanese Pack [l10nja] should package its dependencies.
INFO: Process project properties
INFO: Execute project builders
INFO: Execute project builders (done) | time=7ms
INFO: Project key: com.pearson.ed.ltg.tpi:core
INFO: Base dir: /jenkins/.jenkins/workspace/error_fix_in_tpi_core_test_suit
INFO: Working dir: /jenkins/.jenkins/workspace/error_fix_in_tpi_core_test_suit/.scannerwork
INFO: Load project settings for component key: ‘com.pearson.ed.ltg.tpi:core’
INFO: Load project settings for component key: ‘com.pearson.ed.ltg.tpi:core’ (done) | time=1434ms
INFO: Load quality profiles
INFO: Load quality profiles (done) | time=1333ms
INFO: Detected Jenkins
INFO: Load active rules
INFO: Load active rules (done) | time=27710ms
INFO: Indexing files…
INFO: Project configuration:
INFO: 1021 files indexed
INFO: Quality profile for java: Sonar way
INFO: ------------- Run sensors on module TPI Core Server
INFO: Load metrics repository
INFO: Load metrics repository (done) | time=2856ms
INFO: Sensor JavaSquidSensor [java]
INFO: Configured Java source version (sonar.java.source): none
INFO: JavaClasspath initialization
WARN: Bytecode of dependencies was not provided for analysis of source files, you might end up with less precise results. Bytecode can be provided using sonar.java.libraries property.
INFO: JavaClasspath initialization (done) | time=20ms
INFO: JavaTestClasspath initialization
WARN: Bytecode of dependencies was not provided for analysis of test files, you might end up with less precise results. Bytecode can be provided using sonar.java.test.libraries property.
INFO: JavaTestClasspath initialization (done) | time=2ms
INFO: Java Main Files AST scan
INFO: 863 source files to be analyzed
INFO: Load project repositories
INFO: Load project repositories (done) | time=1545ms
INFO: 23/863 files analyzed, current file: server/src/main/java/com/pearson/ed/tpi/biz/ServiceLogic.java
INFO: 64/863 files analyzed, current file: server/src/main/java/com/pearson/ed/tpi/lms/proxies/ESBWebServiceCourseProxy.java
INFO: 121/863 files analyzed, current file: server/src/main/java/com/pearson/ed/tpi/lti/domain/BasicLTILaunch.java
INFO: 160/863 files analyzed, current file: server/src/main/java/com/pearson/ed/tpi/lti/http/HttpPoster.java
INFO: 212/863 files analyzed, current file: server/src/main/java/com/pearson/ed/tpi/provisioning/client/callback/ProvisioningLoggingInterceptor.java
INFO: 258/863 files analyzed, current file: server/src/main/java/com/pearson/ed/tpi/sso/ExternalLoginIdAlgorithm.java
INFO: 367/863 files analyzed, current file: server/src/main/java/com/pearson/ed/tpi/webservices/generated/xsd/ims/common/imsmessbindschema_v1p0/jaxb/ExtensionField.java
INFO: 569/863 files analyzed, current file: server/src/main/java/com/pearson/ed/tpi/webservices/generated/xsd/ims/lti/tool/SecurityProfileType.java
INFO: 787/863 files analyzed, current file: server/src/main/java/com/pearson/ed/tpi/webservices/generated/xsd/pearson/CreateCourse.java
INFO: 863/863 source files have been analyzed
INFO: Java Main Files AST scan (done) | time=93729ms
INFO: Java Test Files AST scan
INFO: 158 source files to be analyzed
WARN: Invalid character encountered in file /jenkins/.jenkins/workspace/error_fix_in_tpi_core_test_suit/server/src/test/java/com/pearson/ed/tpi/util/logappender/DE1571Test.java at line 89 for encoding UTF-8. Please fix file content or configure the encoding to be used using property ‘sonar.sourceEncoding’.
INFO: Java Test Files AST scan (done) | time=7215ms
INFO: Java Generated Files AST scan
INFO: 0 source files to be analyzed
INFO: Java Generated Files AST scan (done) | time=1ms
INFO: 0/0 source files have been analyzed
INFO: Sensor JavaSquidSensor [java] (done) | time=101278ms
INFO: Sensor CoberturaSensor [cobertura]
INFO: 158/158 source files have been analyzed
INFO: parsing /jenkins/.jenkins/workspace/error_fix_in_tpi_core_test_suit/target/coverageReports/coverage.xml
INFO: ------------------------------------------------------------------------
INFO: EXECUTION FAILURE
INFO: ------------------------------------------------------------------------
INFO: Total time: 2:24.982s
INFO: Final Memory: 42M/1423M
INFO: ------------------------------------------------------------------------
ERROR: Error during SonarScanner execution
java.lang.IllegalStateException: Line number must be strictly positive: 0
at org.sonar.api.internal.google.common.base.Preconditions.checkState(Preconditions.java:197)
at org.sonar.api.batch.sensor.coverage.internal.DefaultCoverage.validateLine(DefaultCoverage.java:94)
at org.sonar.api.batch.sensor.coverage.internal.DefaultCoverage.lineHits(DefaultCoverage.java:81)
at org.sonar.plugins.cobertura.CoberturaReportParser.collectFileData(CoberturaReportParser.java:117)
at org.sonar.plugins.cobertura.CoberturaReportParser.collectFileMeasures(CoberturaReportParser.java:98)
at org.sonar.plugins.cobertura.CoberturaReportParser.collectPackageMeasures(CoberturaReportParser.java:87)
at org.sonar.plugins.cobertura.CoberturaReportParser.parse(CoberturaReportParser.java:67)
at org.sonar.plugins.cobertura.CoberturaReportParser.parseReport(CoberturaReportParser.java:58)
at org.sonar.plugins.cobertura.CoberturaSensor.parseReport(CoberturaSensor.java:72)
at org.sonar.plugins.cobertura.CoberturaSensor.execute(CoberturaSensor.java:66)
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:400)
at org.sonar.scanner.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:395)
at org.sonar.scanner.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:358)
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:73)
at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:67)
at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:46)
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: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)
ERROR:
ERROR: Re-run SonarScanner using the -X switch to enable full debug logging.
WARN: Unable to locate ‘report-task.txt’ in the workspace. Did the SonarScanner succeed?
ERROR: SonarQube scanner exited with non-zero code: 1
Finished: FAILURE

Please let me if I could do anything.

Thanks.

Hello,

Thanks for the logs. We’re a bit back to square one here.
SonarQube apparently fails because it is asked to feed coverage for a non strictly positive line number.
This can be:

  1. Either a problem in the generated coverage file --> You should look at the contents of /jenkins/.jenkins/workspace/error_fix_in_tpi_core_test_suit/target/coverageReports/coverage.xml to check if there is no line nbr < 1
  2. Or a problem in the Cobertura plugin (if the cobertura report has no line nbr < 1), that produces a line < 1 when parsing the report and feeding SonarQube

This is just a guess, but I suspect that you will find out this is case 2 above, and you should therefore open a ticket to the Cobertura plugin. SonarSource cannot help much on this.