Cannot invoke "org.sonar.plugins.php.api.visitors.CheckContext.getWorkingDirectory()"

  • Enterprise Edition Version 9.9.3 (build 79811)

I’m trying to get our PHP project setup in our Enterprise instance, but I’m running into an issue. We have a 3rd party application, though we only want to scan our customizations. Here are my properties:

sonar.sources=custom/
sonar.inclusions=custom/application,custom/clients,custom/src
sonar.exclusions=custom/src/plugin1,custom/src/plugin2,custom/src/plugin3
sonar.tests=custom/tests/unit-php/
sonar.php.tests.reportPath=reports/unittest.xml
sonar.php.coverage.reportPaths=clover.xml

And this is the error I’m seeing:

INFO: Project configuration:
INFO:   Included sources: custom/application, custom/clients, custom/src
INFO:   Excluded sources: custom/src/plugin1, custom/src/plugin2, custom/src/plugin3
INFO: 92 files indexed
INFO: 7583 files ignored because of inclusion/exclusion patterns
INFO: 0 files ignored because of scm ignore settings
INFO: Quality profile for php: Sonar way
INFO: Quality profile for web: Sonar way
INFO: ------------- Run sensors on module myawesomeproject
INFO: Load metrics repository
INFO: Load metrics repository (done) | time=119ms
INFO: Sensor C# Project Type Information [csharp]
INFO: Sensor C# Project Type Information [csharp] (done) | time=6ms
INFO: Sensor C# Analysis Log [csharp]
INFO: Sensor C# Analysis Log [csharp] (done) | time=44ms
INFO: Sensor C# Properties [csharp]
INFO: Sensor C# Properties [csharp] (done) | time=0ms
INFO: Sensor TextAndSecretsSensor [text]
INFO: Sensor TextAndSecretsSensor is restricted to changed files only
INFO: Sensor TextAndSecretsSensor [text] (done) | time=9ms
INFO: Sensor VB.NET Project Type Information [vbnet]
INFO: Sensor VB.NET Project Type Information [vbnet] (done) | time=2ms
INFO: Sensor VB.NET Analysis Log [vbnet]
INFO: Sensor VB.NET Analysis Log [vbnet] (done) | time=13ms
INFO: Sensor VB.NET Properties [vbnet]
INFO: Sensor VB.NET Properties [vbnet] (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=2ms
INFO: Sensor CSS Rules [javascript]
INFO: Sensor CSS Rules is restricted to changed files only
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 ThymeLeaf template sensor [securityjavafrontend]
INFO: Sensor ThymeLeaf template sensor [securityjavafrontend] (done) | time=1ms
INFO: Sensor PHP sensor [php]
INFO: Starting PHP symbol indexer
INFO: 91 source files to be analyzed
INFO: 91/91 source files have been analyzed
INFO: Cached information of global symbols will be used for 91 out of 91 files. Global symbols were recomputed for the remaining files.
INFO: Starting PHP rules
INFO: 91 source files to be analyzed
WARN: An error occurred while trying to terminate checks:
java.lang.NullPointerException: Cannot invoke "org.sonar.plugins.php.api.visitors.CheckContext.getWorkingDirectory()" because the return value of "com.sonar.security.frontend.php.ucfg.H.context()" is null
	at com.sonar.security.frontend.php.ucfg.H.A(na:1559)
	at com.sonar.security.frontend.php.ucfg.H.serializePredefinedTypes(na:1357)
	at com.sonar.security.frontend.php.ucfg.H.terminate(na:1250)
	at com.sonar.security.frontend.php.rules.A.terminate(na:2072)
	at com.sonar.security.frontend.php.rules.SQLInjectionCheck.terminate(na:988)
	at org.sonar.php.PHPAnalyzer.terminate(PHPAnalyzer.java:121)
	at org.sonar.plugins.php.AnalysisScanner.onEnd(AnalysisScanner.java:310)
	at org.sonar.plugins.php.Scanner.execute(Scanner.java:79)
	at org.sonar.plugins.php.Scanner.execute(Scanner.java:62)
	at org.sonar.plugins.php.AnalysisScanner.execute(AnalysisScanner.java:104)
	at org.sonar.plugins.php.PHPSensor.execute(PHPSensor.java:109)
	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:77)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
	at org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:60)
	at jdk.proxy1/jdk.proxy1.$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)

INFO: 91/91 source files have been analyzed
INFO: The PHP analyzer was able to leverage cached data from previous analyses for 0 out of 91 files. These files were not parsed.
INFO: Importing /github/workspace/reports/unittest.xml
INFO: Importing /github/workspace/clover.xml
WARN: Failed to resolve 96 file path(s) in PHPUnit coverage clover.xml report. Nothing is imported related to file(s): custom/clients/base/api/CheckScheduleJobsStatusApi.php;custom/clients/base/api/ControlUsersLoginTimesApi.php;custom/clients/base/api/CreateDocumentRevisionApi.php;custom/clients/base/api/CustomCommissionAPI.php;custom/clients/base/api/CustomOnChangeCalAPI.php;...
INFO: Sensor PHP sensor [php] (done) | time=3917ms

I’m not really sure what the source of the NullPointerException could be, and wasn’t able to find any relevant results on Google.

Any ideas?

Hey @johnh1,

welcome to the community! Sorry to see that you are having this problem.

Can you try the analysis with the property sonar.analysisCache.enabled set to false?

Sorry for the delay. I did manage to get it mostly working, including the clover and phpunit coverage reports.

I found I had to set something like:
sources: custom/folder1,custom/folder2,custom/folder3

rather than

sources: custom
inclusions: custom/folder,custom/folder2,etc

Which seemed rather inconvenient, and I don’t think the use case was covered in the documentation. We’ve spent the past 2 years trying to add code coverage over our customization made to a legacy application, and phpunit’s coverage reports us at 86% while sonarqube reports 30%, so a lot of it is fine tuning what is being scanned.

1 Like