Docker sonar-scanner-cli NullPointerException

My project is just a 5 file python thing.

  • versions used (SonarQube, Scanner, Plugin, and any relevant extension)
    Everything is used in docker containers:
    sonarqube:8.9.7-community
    sonarsource/sonar-scanner-cli:4.6

  • error observed

WARN: Unable to analyze file: config.py
java.lang.NullPointerException: null
        at org.sonar.python.semantic.SymbolUtils.fullyQualifiedModuleName(SymbolUtils.java:79)
        at org.sonar.python.semantic.SymbolTableBuilder.<init>(SymbolTableBuilder.java:118)
        at org.sonar.plugins.python.api.PythonVisitorContext.<init>(PythonVisitorContext.java:56)
        at org.sonar.plugins.python.PythonScanner.scanFile(PythonScanner.java:109)
        at org.sonar.plugins.python.Scanner.execute(Scanner.java:52)
        at org.sonar.plugins.python.PythonSensor.execute(PythonSensor.java:84)
        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: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:112)
        at org.sonarsource.scanner.cli.Main.execute(Main.java:75)
        at org.sonarsource.scanner.cli.Main.main(Main.java:61)
  • steps to reproduce
docker run --rm --user="$(id -u):$(id -g)" -e SONAR_HOST_URL="http://sonarqube:9000/sonarqube" -v "`pwd`:/usr/src" --network docker-gitlab_gitlab sonarsource/sonar-scanner-cli:4.5 -Dsonar.projectKey=projectnamehere -Dsonar.scm.provider=git -Dsonar.working.directory=/tmp/.scannerwork -Dsonar.login=tokenhere
  • potential workaround
    No idea.

Migrated to sonarqube:9.3.0-community

now I only get this message at the end. Looks like the same one that showed up at the end of 8.9.7. The one above doesn’t show up anymore.

16:07:33.209 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: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:136)
        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: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:112)
        at org.sonarsource.scanner.cli.Main.execute(Main.java:75)
        at org.sonarsource.scanner.cli.Main.main(Main.java:61)

Hi,

Thanks for reporting this. Can you share a reproducer, please?

 
Thx,
ann

By reproducer you mean a file that causes that error?

# docker run --rm -e SONAR_HOST_URL="http://sonarqube:9000/sonarqube" -v "`pwd`:/usr/src" --network docker-gitlab_gitlab sonarsource/sonar-scanner-cli:4.6 -Dsonar.projectKey=nsa9pybot -Dsonar.working.directory=/usr/.scannerwork -Dsonar.login=4b358272f9a75fa6b3e5486b1890067633708e97 -Dsonar.python.version=3.9

INFO: Scanner configuration file: /opt/sonar-scanner/conf/sonar-scanner.properties
INFO: Project root configuration file: NONE
INFO: SonarScanner 4.6.2.2472
INFO: Java 11.0.14 Alpine (64-bit)
INFO: Linux 5.10.61-gentoo-x86_64 amd64
INFO: User cache: /opt/sonar-scanner/.sonar/cache
INFO: Scanner configuration file: /opt/sonar-scanner/conf/sonar-scanner.properties
INFO: Project root configuration file: NONE
INFO: Analyzing on SonarQube server 9.3.0
INFO: Default locale: "en_US", source code encoding: "UTF-8" (analysis is platform dependent)
INFO: Load global settings
INFO: Load global settings (done) | time=60ms
INFO: Server id: B7285AAD-AXRzjAKIfkb01VGLth8x
INFO: User cache: /opt/sonar-scanner/.sonar/cache
INFO: Load/download plugins
INFO: Load plugins index
INFO: Load plugins index (done) | time=41ms
INFO: Load/download plugins (done) | time=1315ms
INFO: Process project properties
INFO: Process project properties (done) | time=0ms
INFO: Execute project builders
INFO: Execute project builders (done) | time=1ms
INFO: Project key: nsa9pybot
INFO: Base dir: /usr/src
INFO: Working dir: /usr/.scannerwork
INFO: Load project settings for component key: 'nsa9pybot'
INFO: Load project settings for component key: 'nsa9pybot' (done) | time=12ms
INFO: Load quality profiles
INFO: Load quality profiles (done) | time=34ms
INFO: Load active rules
INFO: Load active rules (done) | time=877ms
WARN: SCM provider autodetection failed. Please use "sonar.scm.provider" to define SCM of your project, or disable the SCM Sensor in the project settings.
INFO: Indexing files...
INFO: Project configuration:
INFO: 1 file indexed
INFO: Quality profile for py: Sonar way
INFO: ------------- Run sensors on module nsa9pybot
INFO: Load metrics repository
INFO: Load metrics repository (done) | time=20ms
INFO: Sensor Python Sensor [python]
INFO: Starting global symbols computation
INFO: 1 source file to be analyzed
INFO: Load project repositories
INFO: 1/1 source file has been analyzed
INFO: Starting rules execution
INFO: 1 source file to be analyzed
INFO: 1/1 source file has been analyzed
INFO: Sensor Python Sensor [python] (done) | time=518ms
INFO: Sensor Cobertura Sensor for Python coverage [python]
INFO: Sensor Cobertura Sensor for Python coverage [python] (done) | time=8ms
INFO: Sensor PythonXUnitSensor [python]
INFO: Sensor PythonXUnitSensor [python] (done) | time=0ms
INFO: Sensor JaCoCo XML Report Importer [jacoco]
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
INFO: No report imported, no coverage information will be imported by JaCoCo XML Report Importer
INFO: Sensor JaCoCo XML Report Importer [jacoco] (done) | time=3ms
INFO: Sensor CSS Rules [javascript]
INFO: No CSS, PHP, HTML or VueJS files are found in the project. CSS analysis is skipped.
INFO: Sensor CSS Rules [javascript] (done) | time=1ms
INFO: Sensor C# Project Type Information [csharp]
INFO: Sensor C# Project Type Information [csharp] (done) | time=0ms
INFO: Sensor C# Analysis Log [csharp]
INFO: Sensor C# Analysis Log [csharp] (done) | time=11ms
INFO: Sensor C# Properties [csharp]
INFO: Sensor C# Properties [csharp] (done) | time=0ms
INFO: Sensor HTML [web]
INFO: Sensor HTML [web] (done) | time=2ms
INFO: Sensor Text Sensor [text]
INFO: 1 source file to be analyzed
INFO: 1/1 source file has been analyzed
INFO: Sensor Text Sensor [text] (done) | time=7ms
INFO: Sensor VB.NET Project Type Information [vbnet]
INFO: Sensor VB.NET Project Type Information [vbnet] (done) | time=1ms
INFO: Sensor VB.NET Analysis Log [vbnet]
INFO: Sensor VB.NET Analysis Log [vbnet] (done) | time=14ms
INFO: Sensor VB.NET Properties [vbnet]
INFO: Sensor VB.NET Properties [vbnet] (done) | time=0ms
INFO: ------------- Run sensors on project
INFO: Sensor Zero Coverage Sensor
INFO: Sensor Zero Coverage Sensor (done) | time=7ms
INFO: SCM Publisher No SCM system was detected. You can use the 'sonar.scm.provider' property to explicitly specify it.
INFO: CPD Executor Calculating CPD for 1 file
INFO: CPD Executor CPD calculation finished (done) | time=9ms
INFO: ------------------------------------------------------------------------
INFO: EXECUTION FAILURE
INFO: ------------------------------------------------------------------------
INFO: Total time: 5.531s
INFO: Final Memory: 18M/120M
INFO: ------------------------------------------------------------------------
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: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:136)
        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: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: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.
# cat t.py

import numpy as np


def getpixelinfo(location):
    pixels = {
            "A": {
                "pixelsx": np.array([81, 107, 108, 81, 64, 84, 157, 179, 172], dtype=int),
                "pixelsy": np.array([55, 55, 97, 98, 158, 169, 170, 147, 191], dtype=int),
                "expected": np.array([255, 255, 255, 255, 255, 0, 255, 0, 0], dtype=int)
            },
            "B": {
                "pixelsx": np.array([28, 210, 1271, 106, 497, 1292, 1689, 1682, 1672, 1413, 1299, 1710, 491, 76, 126,
                                     578, 92, 288, 460, 762, 924, 1479, 1745, 1308, 1528, 1618, 1400, 303, 89,
                                     804], dtype=int),
                "pixelsy": np.array([53, 44, 41, 391, 372, 399, 402, 264, 619, 620, 784, 782, 806, 779, 566, 568, 964,
                                     968, 965, 912, 916, 946, 935, 1059, 1059, 1057, 1057, 1055, 1053,
                                     1058], dtype=int),
                "expected": np.array([0, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 0, 0, 255,
                                      255, 0, 0, 0, 0, 255], dtype=int)
            },
            "C": {
                # just press play
                "pixelsx": np.array([23, 20, 104, 361, 1246, 1521, 1804, 1840, 1689, 1423, 593, 91, 115, 572, 1426,
                                     1786, 1798, 1306, 73, 315, 425, 672, 1246, 1499, 1612, 1839, 1850, 1565, 501, 380,
                                     108, 110, 643, 1357, 1701], dtype=int),
                "pixelsy": np.array([18, 115, 27, 44, 49, 43, 261, 288, 282, 287, 267, 283, 474, 460, 477, 465, 636,
                                     605, 647, 736, 743, 744, 739, 748, 758, 763, 996, 979, 968, 991, 973, 1058, 1057,
                                     1067, 1057], dtype=int),
                "expected": np.array([255, 255, 255, 255, 0, 0, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255,
                                      255, 255, 0, 0, 0, 0, 255, 0, 0, 0, 0, 0, 0], dtype=int)
            },
            "D": {
                "pixelsx": np.array([19, 23, 108, 363, 1487, 1863, 23, 30, 35, 37, 294, 424, 530, 635, 794, 919, 962,
                                     1058, 1214, 1307, 1419, 1528, 1590, 1689, 1755, 1839, 1858, 438, 1046, 1525,
                                     1858], dtype=int),
                "pixelsy": np.array([19, 102, 34, 47, 41, 39, 240, 593, 1019, 1050, 1057, 1058, 1054, 1058, 1057, 1046,
                                     1045, 1059, 1059, 1057, 1059, 1057, 1059, 1053, 1057, 1061, 997, 244, 251, 258,
                                     261], dtype=int),
                "expected": np.array([255, 255, 255, 255, 0, 255, 0, 0, 0, 0, 0, 255, 0, 255, 0, 255, 255, 0, 0, 255,
                                      0, 255, 0, 0, 255, 0, 0, 0, 0, 0, 0], dtype=int)
            },
            "E": {
                "pixelsx": np.array([24, 111, 30, 361, 1246, 1490, 1866, 139, 280, 418, 426, 279, 130, 754, 732, 736,
                                     176, 403, 605, 440, 453, 486, 429, 352, 552, 622, 480], dtype=int),
                "pixelsy": np.array([19, 27, 90, 47, 43, 37, 41, 911, 912, 907, 986, 997, 991, 540, 521, 556, 811, 814,
                                     807, 681, 575, 479, 354, 269, 275, 983, 955], dtype=int),
                "expected": np.array([255, 255, 255, 255, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0,
                                      0, 0, 0, 0, 0, 0, 0, 255, 255], dtype=int)
            },
            "F": {
                "pixelsx": np.array([428, 621, 816, 1269, 1637, 1837, 1837, 1796, 1795, 1252, 1148, 1130, 1079, 1074,
                                     1005, 1024, 1043, 1018, 958, 904, 859, 740, 695, 116, 817, 1643, 1461,
                                     144], dtype=int),
                "pixelsy": np.array([50, 48, 54, 64, 40, 360, 402, 402, 359, 544, 545, 501, 558, 509, 514, 510, 506,
                                     543, 550, 550, 547, 548, 446, 612, 606, 613, 1015, 1009], dtype=int),
                "expected": np.array([0, 0, 0, 0, 0, 255, 255, 255, 255, 0, 0, 255, 255, 0, 255, 0, 255, 0, 255, 0,
                                      255, 0, 0, 0, 0, 0, 0, 0], dtype=int)
            },
            "G": {
                "pixelsx": np.array([336, 438, 944, 908, 392, 596, 1110, 88, 348, 566], dtype=int),
                "pixelsy": np.array([80, 78, 84, 148, 144, 110, 154, 160, 192, 184], dtype=int),
                "expected": np.array([0, 255, 255, 255, 255, 255, 255, 0, 0, 0], dtype=int)
            },
            "H": {
                "pixelsx": np.array([28, 108, 36, 358, 1864, 662, 974, 1338, 44, 36, 234, 922, 946, 770, 1368, 1398,
                                     1214, 1816, 1844, 1674, 40, 1292, 1878], dtype=int),
                "pixelsy": np.array([22, 36, 82, 42, 36, 284, 294, 306, 496, 576, 668, 584, 586, 792, 586, 586, 818,
                                     582, 584, 788, 1016, 1008, 1004], dtype=int),
                "expected": np.array([255, 255, 255, 255, 255, 0, 0, 0, 0, 0, 255, 255, 255, 0, 255, 255, 0, 255, 255,
                                      0, 0, 0, 0], dtype=int)
            },
            "I": {
                "pixelsx": np.array([48, 1808, 872, 1472, 858, 180, 1278, 1772, 1206, 836, 146, 46, 316, 670, 1108,
                                     232, 176, 240, 974, 1488, 1722, 1822, 1708, 1076], dtype=int),
                "pixelsy": np.array([34, 90, 392, 364, 264, 648, 742, 688, 768, 982, 820, 976, 86, 196, 148, 934, 934,
                                     660, 770, 626, 876, 428, 124, 246], dtype=int),
                "expected": np.array([0, 0, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 255, 0, 255, 255, 0, 0, 0, 0, 0, 0,
                                      0], dtype=int,)
            }
    }

    try:
        return pixels[location]["pixelsx"], pixels[location]["pixelsy"], pixels[location]["expected"]
    except KeyError:
        return np.array([], dtype=int), np.array([], dtype=int), np.array([], dtype=int)
1 Like

Nevermind me. I’m dumb. -X seems to yell a:

19:31:25.013 INFO: Load project repositories
19:31:25.017 DEBUG: GET 403 http://sonarqube:9000/sonarqube/batch/project.protobuf?key=nsa9pybot | time=4ms
19:31:25.017 DEBUG: Unable to construct project-level symbol table for file: t.py
19:31:25.017 DEBUG: You're not authorized to run analysis. Please contact the project administrator.
19:31:25.018 INFO: 1/1 source file has been analyzed
19:31:25.018 INFO: Starting rules execution
19:31:25.018 INFO: 1 source file to be analyzed
19:31:25.474 DEBUG: Symbol Literal has conflicting fully qualified names:typing.Literal,typing_extensions.Literal
19:31:25.474 DEBUG: It has been disambiguated with its latest Python version available symbol.
19:31:25.512 INFO: 1/1 source file has been analyzed

Changing permissions on the project to allow code analysis to admin / sonar-administrator seems to be working. I’d expect it to yell something else and not a NPE though. Something more explicit and useful.

1 Like

Hi,

I’m glad you worked through this.

Fair point. I’d also have expected the error to crop up earlier (and not just in DEBUG logging). I’ll bring this up internally.

 
Ann

I created a ticket: [SONAR-16050] Scanner fails with NPE if user doesn't have permission to analyze project - SonarSource.
I think it’s a regression so I’m categorizing it as a bug.

1 Like

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