Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NullPointerException when running SonarScanner #28

Open
JonathanNakandala opened this issue Jun 28, 2022 · 15 comments
Open

NullPointerException when running SonarScanner #28

JonathanNakandala opened this issue Jun 28, 2022 · 15 comments

Comments

@JonathanNakandala
Copy link

I get this crash on the sonar-scanner.

I did try all sorts of tokens and it hasn't seemed to make a difference.
Is there perhaps something I can do to do more debugging?

Run settings:

      sonar-scanner
      -Dsonar.host.url=$SONAR_URL
      -Dsonar.gitlab.project_id=$CI_PROJECT_PATH
      -Dsonar.gitlab.commit_sha=$CI_COMMIT_SHA
      -Dsonar.gitlab.ref_name=$CI_COMMIT_REF_NAME
      -Dsonar.gitlab.user_token=$SONAR_GITLAB_TOKEN
      -Dsonar.gitlab.url=https:/mygitlab.com
      -Dsonar.gitlab.ci_merge_request_iid=$CI_MERGE_REQUEST_IID
      -Dsonar.gitlab.merge_request_discussion=true

There's also a sonar-project.properties with:

sonar.projectKey=<MyProjectKey>
sonar.qualitygate.wait=true
sonar.python.version=3.8
sonar.exclusions=<FoldersList>
sonar.python.pylint.reportPaths=public/lint/parseable.txt
sonar.python.xunit.reportPath=report.xml
sonar.python.coverage.reportPaths=coverage.xml
sonar.sources=<foldersList>
sonar.tests=tests

Version: 5.2.1
Sonarqube version: Version 9.5 (build 56709)

java.lang.NullPointerException
	at com.talanlabs.sonar.plugins.gitlab.GitLabApiV4Wrapper.createOrUpdateSonarQubeStatus(GitLabApiV4Wrapper.java:223)
	at com.talanlabs.sonar.plugins.gitlab.CommitFacade.createOrUpdateSonarQubeStatus(CommitFacade.java:124)
	at com.talanlabs.sonar.plugins.gitlab.CommitPublishPostJob.execute(CommitPublishPostJob.java:111)
	at org.sonar.scanner.postjob.PostJobWrapper.execute(PostJobWrapper.java:49)
	at org.sonar.scanner.postjob.PostJobsExecutor.execute(PostJobsExecutor.java:48)
	at org.sonar.scanner.postjob.PostJobsExecutor.execute(PostJobsExecutor.java:39)
	at org.sonar.scanner.scan.SpringProjectScanContainer.doAfterStart(SpringProjectScanContainer.java:372)
	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:135)
	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:112)
	at org.sonarsource.scanner.cli.Main.execute(Main.java:75)
	at org.sonarsource.scanner.cli.Main.main(Main.java:61)
@javamachr
Copy link
Owner

Seems like config issue - one of projecId or refName is empty. Check $CI_COMMIT_REF_NAME or $CI_PROJECT_PATH value if it is correctly set.

@JonathanNakandala
Copy link
Author

Thanks for replying! :)

I added a couple of echoes before the sonar-scanner, it does have values.

$ echo $CI_COMMIT_REF_NAME
experiment-gitlab
$ echo $CI_PROJECT_PATH
jonoGroup/testrepo

@javamachr
Copy link
Owner

The project ID value is wrong. It is not path it should be ID of project(it is queried by ID via API) that you can find on project page:
img

@JonathanNakandala
Copy link
Author

hmmm, so I manually set it to the value in the config file:

sonar.gitlab.project_id=1452

And also tried setting it with -D

Looks like I'm getting the same error still

11:28:27.580 DEBUG: Post-jobs : GitLab Commit Issue Publisher
11:28:27.581 INFO: Executing post-job 'GitLab Commit Issue Publisher'
11:28:27.581 INFO: Will execute CommitPublishPostJob of GitlabPlugin.
11:28:27.581 INFO: GitLab plugin is enabled
11:28:27.846 INFO: ------------------------------------------------------------------------
11:28:27.846 INFO: EXECUTION FAILURE
11:28:27.846 INFO: ------------------------------------------------------------------------
11:28:27.846 INFO: Total time: 1:33.684s
11:28:28.116 ERROR: Error during SonarScanner execution
11:28:28.116 INFO: Final Memory: 45M/360M
11:28:28.116 INFO: ------------------------------------------------------------------------
java.lang.NullPointerException
	at com.talanlabs.sonar.plugins.gitlab.GitLabApiV4Wrapper.createOrUpdateSonarQubeStatus(GitLabApiV4Wrapper.java:223)
	at com.talanlabs.sonar.plugins.gitlab.CommitFacade.createOrUpdateSonarQubeStatus(CommitFacade.java:124)
	at com.talanlabs.sonar.plugins.gitlab.CommitPublishPostJob.execute(CommitPublishPostJob.java:111)
	at org.sonar.scanner.postjob.PostJobWrapper.execute(PostJobWrapper.java:49)
	at org.sonar.scanner.postjob.PostJobsExecutor.execute(PostJobsExecutor.java:48)
	at org.sonar.scanner.postjob.PostJobsExecutor.execute(PostJobsExecutor.java:39)
	at org.sonar.scanner.scan.SpringProjectScanContainer.doAfterStart(SpringProjectScanContainer.java:372)
	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:135)
	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:112)
	at org.sonarsource.scanner.cli.Main.execute(Main.java:75)
	at org.sonarsource.scanner.cli.Main.main(Main.java:61)

btw, I copied using the proejct path for the id from the readme.md:

https://github.com/javamachr/sonar-gitlab-plugin/blob/master/README.md#gitlab-ci

@javamachr
Copy link
Owner

It seems that it fails to find the project via API. This

-Dsonar.gitlab.url=https:/mygitlab.com

seems like a wrong value - could you please double check that it is correctly pointed to your GL instance? This part of code should not be broken - must be config related I'd say.

@git22ura
Copy link

git22ura commented Nov 7, 2022

Hi!
I also catch this error.
The report is completed, but no comments in MR.
Can the Java version or other dependencies somehow affect?

Settings:

Plugin: 5.3.0
SonarQube: Community Edition 9.6.1 (build 59531)

SonarQube plugins:
  - GitLab 5.3.0 (gitlab)
  - Community Branch Plugin 1.12.0 (communityBranchPlugin)
Global server settings:
  - sonar.gitlab.url=https://git/
  - sonar.gitlab.user_token=************
Project scanner properties:
  - sonar.gitlab.ci_merge_request_iid=43
  - sonar.gitlab.comment_no_issue=true
  - sonar.gitlab.commit_sha=*************
  - sonar.gitlab.project_id=410
  - sonar.gitlab.ref_name=web-1
  - sonar.host.url=http://**********:9000/
  - sonar.login=******
  - sonar.qualitygate.wait=true
  - sonar.scanner.app=ScannerCLI
  - sonar.scanner.appVersion=4.7.0.2747

Log:

INFO: ------------- Check Quality Gate status
INFO: Waiting for the analysis report to be processed (max 300s)
INFO: QUALITY GATE STATUS: PASSED - View details on http://******************
INFO: Executing post-job 'GitLab Commit Issue Publisher'
INFO: Will execute CommitPublishPostJob of GitlabPlugin.
INFO: GitLab plugin is enabled
INFO: ------------------------------------------------------------------------
INFO: EXECUTION FAILURE
INFO: ------------------------------------------------------------------------
INFO: Total time: 1:09.068s
INFO: Final Memory: 87M/304M
INFO: ------------------------------------------------------------------------

ERROR: Error during SonarScanner execution
java.lang.NullPointerException
	at com.talanlabs.sonar.plugins.gitlab.GitLabApiV4Wrapper.createOrUpdateSonarQubeStatus(GitLabApiV4Wrapper.java:221)
	at com.talanlabs.sonar.plugins.gitlab.CommitFacade.createOrUpdateSonarQubeStatus(CommitFacade.java:124)
	at com.talanlabs.sonar.plugins.gitlab.CommitPublishPostJob.execute(CommitPublishPostJob.java:111)
	at org.sonar.scanner.postjob.PostJobWrapper.execute(PostJobWrapper.java:49)
	at org.sonar.scanner.postjob.PostJobsExecutor.execute(PostJobsExecutor.java:48)
	at org.sonar.scanner.postjob.PostJobsExecutor.execute(PostJobsExecutor.java:39)
	at org.sonar.scanner.scan.SpringProjectScanContainer.doAfterStart(SpringProjectScanContainer.java:376)
	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:135)
	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(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)

@javamachr
Copy link
Owner

It is checking gitlab API using sonar.gitlab.url=https://git/ and projectId and it obviously fails since https://git/ seems to be wrong value and no gitlab server is running there I assume.

@SergeyKraynev
Copy link

Thanks for your reply. The URL is correct, the standard SonarQube mechanism sends its comments perfectly.

@javamachr
Copy link
Owner

Hmm can you try to call the API from sonar machine/container via CURL? It should give you some hints. For some reason sonarqube is unable to reach gitlab api calls.
Just try to call smt like:

curl --header "PRIVATE-TOKEN: <your_access_token>" "https://git/api/v4/projects/410/repository/commits"

And see if it returns something or fails.

@git22ura
Copy link

git22ura commented Nov 9, 2022

It is ok. There is windows server.

StatusCode        : 200
StatusDescription : OK
Content           : [{"id":"656ce92a6faacb2ea1c0a89dfc5d898af49cf74c","short_id":"656ce92a","created_at":"2022-11-09T12:08:53.000+03:00","parent_ids":["574fc7c96167fe325
                    563991d7f10cdcf444b007b"],"title":"testtttttt...
RawContent        : HTTP/1.1 200 OK
                    Transfer-Encoding: chunked
                    Connection: keep-alive
                    Vary: Accept-Encoding,Origin
                    Link: <https://git/api/v4/projects/410/repository/commits?id=410&order=default&page=2&per_page=20&tra...
Forms             : {}
Headers           : {[Transfer-Encoding, chunked], [Connection, keep-alive], [Vary, Accept-Encoding,Origin], [Link, 
                    <https://git/api/v4/projects/410/repository/commits?id=410&order=default&page=2&per_page=20&trailers=false>; rel="next", 
                    <https://git/api/v4/projects/410/repository/commits?id=410&order=default&page=1&per_page=20&trailers=false>; rel="first", 
                    <https://git/api/v4/projects/410/repository/commits?id=410&order=default&page=2&per_page=20&trailers=false>; rel="last"]...}
Images            : {}
InputFields       : {}
Links             : {}
ParsedHtml        : System.__ComObject
RawContentLength  : 17348  

@javamachr
Copy link
Owner

Hmm then it might be related to JAVA not working with that URL.
What certificate do you use on gitlab instance?
With self signed you might need to add CA to your java installation inside sonar so that java process is able to open https.
Maybe a simple java app trying to do the same as CURL did would help to troubleshoot it.

@krejcmat
Copy link

I have the same issue. Have any of you solved the problem? Thanks

@moreorover
Copy link

Having same issue. here as well.

GitLab 15.11
SonarQube 9.9.1
Sonar Gitlab Plugin 5.3.0

Since this is a null exception I reckon there are not enough checks to provide user with a meaningful error message. Any tips trying to resolve it?

@krejcmat
Copy link

I solved it by using sonarqube admin token. The project token wasn't enough..

@moreorover
Copy link

moreorover commented Jun 17, 2023

I solved it by using sonarqube admin token. The project token wasn't enough..

Anyone facing this issue please make sure first that your technical user gitlab access token is valid by performing the following curl operation:
curl --header "PRIVATE-TOKEN: <your private token>" "https://gitlab.com/api/v4/projects/:id"

I have discovered that the access token I was trying to use was returning 403 response code, when updated the token everything worked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants