SonarScanner CLI v4.3 errors out with NullPointerException

I’m trying to leverage SonarScanner CLI v4.3 to call SonarQube analysis and running into a NullPointerException. I think i’m missing some configuration but unable to figure it out. Any help is highly appreciated? Below are the details -

SonarQube v8.3 and Scanner cli version v4.3

Plugins ->
14:50:53.815 DEBUG: Plugins:
14:50:53.816 DEBUG: * SonarPython 2.8.0.6204 (python)
14:50:53.817 DEBUG: * SonarCSS 1.2.0.1325 (cssfamily)
14:50:53.817 DEBUG: * JaCoCo 1.1.0.898 (jacoco)
14:50:53.818 DEBUG: * SonarGo 1.6.0.719 (go)
14:50:53.818 DEBUG: * SonarKotlin 1.5.0.315 (kotlin)
14:50:53.818 DEBUG: * Svn 1.9.0.1295 (scmsvn)
14:50:53.819 DEBUG: * SonarJS 6.2.0.12043 (javascript)
14:50:53.819 DEBUG: * SonarRuby 1.5.0.315 (ruby)
14:50:53.820 DEBUG: * SonarScala 1.5.0.315 (sonarscala)
14:50:53.820 DEBUG: * C# Code Quality and Security 8.6.1.17183 (csharp)
14:50:53.821 DEBUG: * Java Code Quality and Security 6.3.0.21585 (java)
14:50:53.821 DEBUG: * SonarHTML 3.2.0.2082 (web)
14:50:53.821 DEBUG: * Git 1.11.1.2008 (scmgit)
14:50:53.822 DEBUG: * SonarFlex 2.5.1.1831 (flex)
14:50:53.823 DEBUG: * SonarXML 2.0.1.2020 (xml)
14:50:53.823 DEBUG: * SonarPHP 3.3.0.5166 (php)
14:50:53.823 DEBUG: * SonarTS 2.1.0.4359 (typescript)
14:50:53.824 DEBUG: * VB.NET Code Quality and Security 8.6.1.17183 (vbnet)

Execution Command -

  1. mvn clean verify

  2. sonar-scanner.bat -Dsonar.projectName=abc -Dsonar.projectKey=abc:feature -Dsonar.projectVersion=1.0.1 -Dsonar.login=XXX -Dsonar.password=*******


Some relevant Log section -


14:51:10.512 INFO: Sensor JaCoCo XML Report Importer [jacoco]
14:51:10.520 INFO: 'sonar.coverage.jacoco.xmlReportPaths' is not defined. Using default locations: target/site/jacoco/jacoco.xml,target/site/jacoco-it/jacoco.xml,build/reports/jacoco/test/jacocoTestReport.xml
14:51:10.523 INFO: Importing 1 report(s). Turn your logs in debug mode in order to see the exhaustive list.
14:51:10.523 DEBUG: Reading report 'C:\ABC\ocpsamples\ocpsamples\spring-boot\target\site\jacoco\jacoco.xml'
14:51:10.560 INFO: Sensor JaCoCo XML Report Importer [jacoco] (done) | time=49ms
14:51:10.561 INFO: Sensor SurefireSensor [java]
14:51:10.563 INFO: parsing [C:\ABC\ocpsamples\ocpsamples\spring-boot\target\surefire-reports]
14:51:10.597 DEBUG: Class not found in resource cache : hello.HelloControllerTest
14:51:10.599 DEBUG: Class not found in resource cache : hello.HelloControllerTest
14:51:10.599 DEBUG: Class not found in resource cache : hello.HelloControllerTest
14:51:10.600 DEBUG: Class not found in resource cache : hello.HelloControllerTest
14:51:10.600 DEBUG: Resource not found: hello.HelloControllerTest
14:51:10.600 INFO: Sensor SurefireSensor [java] (done) | time=39ms
14:51:10.602 INFO: Sensor JavaXmlSensor [java]
14:51:10.605 INFO: Sensor JavaXmlSensor [java] (done) | time=3ms
14:51:10.605 INFO: Sensor HTML [web]
14:51:10.642 INFO: Sensor HTML [web] (done) | time=37ms
14:51:10.648 INFO: ------------- Run sensors on project
14:51:10.654 DEBUG: 'Generic Coverage Report' skipped because one of the required properties is missing
14:51:10.655 DEBUG: Sensors : Zero Coverage Sensor -> Java CPD Block Indexer
14:51:10.657 INFO: Sensor Zero Coverage Sensor
14:51:10.659 INFO: Sensor Zero Coverage Sensor (done) | time=2ms
14:51:10.659 INFO: Sensor Java CPD Block Indexer
14:51:10.672 DEBUG: Populating index from src/test/java/hello/HelloControllerIT.java
14:51:10.688 DEBUG: Populating index from src/main/java/hello/HelloController.java
14:51:10.691 DEBUG: Not enough content in 'src/main/java/hello/HelloController.java' to have CPD blocks, it will not be part of the duplication detection
14:51:10.691 DEBUG: Populating index from src/main/java/hello/Application.java
14:51:10.694 DEBUG: Populating index from src/test/java/hello/HelloControllerTest.java
14:51:10.699 INFO: Sensor Java CPD Block Indexer (done) | time=40ms
14:51:10.703 INFO: SCM Publisher SCM provider for this project is: git
-------------
Sonar Project Properties =>
-------------

sonar.sources=src
sonar.java.binaries=target/classes,target/test-classes
sonar.java.coveragePlugin=jacoco


----------------
POM.xml
-------------

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.springframework</groupId>
    <artifactId>gs-spring-boot</artifactId>
    <version>0.1.0</version>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.3.RELEASE</version>
    </parent>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <!-- tag::actuator[] -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <!-- end::actuator[] -->
        <!-- tag::tests[] -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <!-- end::tests[] -->
    </dependencies>

    <properties>
        <java.version>1.8</java.version>
    </properties>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
            </plugin>
            <plugin>
                <groupId>org.sonarsource.scanner.maven</groupId>
                <artifactId>sonar-maven-plugin</artifactId>
                <version>3.6.0.1398</version>
            </plugin>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>           
            <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>0.8.4</version>
            </plugin>
        </plugins>
    </build>
    <profiles>
    <profile>
      <id>coverage</id>
      <activation>
        <activeByDefault>true</activeByDefault>
      </activation>
      <build>
        <plugins>
          <plugin>
            <groupId>org.jacoco</groupId>
            <artifactId>jacoco-maven-plugin</artifactId>
            <executions>
              <execution>
                <id>prepare-agent</id>
                <goals>
                  <goal>prepare-agent</goal>
                </goals>
              </execution>
              <execution>
                <id>report</id>
                <goals>
                  <goal>report</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>
</project>

-----
Exception -

14:51:12.297 ERROR: Error during SonarScanner execution
java.lang.NullPointerException
        at org.sonar.scanner.report.ComponentsPublisher.convert(ComponentsPublisher.java:103)
        at org.sonar.scanner.report.ComponentsPublisher.publish(ComponentsPublisher.java:68)
        at org.sonar.scanner.report.ReportPublisher.generateReportFile(ReportPublisher.java:163)
        at org.sonar.scanner.report.ReportPublisher.execute(ReportPublisher.java:137)
        at org.sonar.scanner.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:359)
        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:141)
        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(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)

I was able to resolve this. It turned out to be an issue with project access.

1 Like

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