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

Please don't block the flow(just ignore the PR which missing the pull_request_binary). #759

Closed
bbxfnet opened this issue Apr 20, 2023 · 4 comments
Labels
bug Something isn't working question Further information is requested

Comments

@bbxfnet
Copy link

bbxfnet commented Apr 20, 2023

Describe the bug

java.lang.NullPointerException: Pull request data should be available for branch type PULL_REQUEST
	at java.base/java.util.Objects.requireNonNull(Unknown Source)
	at com.github.mc1arke.sonarqube.plugin.server.pullrequest.ws.pullrequest.action.ListAction.addPullRequest(ListAction.java:123)
	at com.github.mc1arke.sonarqube.plugin.server.pullrequest.ws.pullrequest.action.ListAction.lambda$handleProjectRequest$2(ListAction.java:102)
	at java.base/java.util.ArrayList.forEach(Unknown Source)
	at com.github.mc1arke.sonarqube.plugin.server.pullrequest.ws.pullrequest.action.ListAction.handleProjectRequest(ListAction.java:102)
	at com.github.mc1arke.sonarqube.plugin.server.pullrequest.ws.pullrequest.action.ProjectWsAction.handle(ProjectWsAction.java:61)

To Reproduce
Steps to reproduce the behavior:
Unknow the reason which the PR don't have pull_request_binary data

Expected behavior
Please don't block the flow(just ignore the PR which missing the pull_request_binary).

Screenshots
None

Software Versions

  • SonarQube Version: sonar-application-9.9.0.65466.jar
  • Plugin Version: sonarqube-community-branch-plugin-1.14.0.jar

Additional context
None

@bbxfnet bbxfnet added the bug Something isn't working label Apr 20, 2023
@mc1arke
Copy link
Owner

mc1arke commented Apr 22, 2023

The error you're hitting indicates that a pull request is recorded in the database, but that it has no data recorded against it. This is definitely invalid (you have a pull request with no source branch) so I'd need you to provide more information about what the data in the database looks like, and also any other information you can think of (i.e. is this a new project that auto-created in an invalid state or one that has existed with working branches and PRs until now, is this only impacting one project are multiple ones, do you actively do anything like deleting PRs or branches from Sonarqube etc).

I don't think that removing that check is necessarily the right direction to go in since it's highlighting that something elsewhere in this plugin - or in your wider Sonarqube instance - is generating invalid data, and this could lead to further issues for you elsewhere.

@mc1arke mc1arke added the question Further information is requested label Apr 22, 2023
@mc1arke
Copy link
Owner

mc1arke commented May 4, 2023

Closing as not-planned given there's no replication steps on this, and the check if there to prevent Sonarqube doing things that may further damage a project that already contains invalid data.

@mc1arke mc1arke closed this as not planned Won't fix, can't repro, duplicate, stale May 4, 2023
@saurabh-sp-tripathi
Copy link

We encountered the same issue and realized the root cause was the specific rows of table SONAR_MAIN.PROJECT_BRANCHES where BRANCH_TYPE = PULL_REQUEST AND MERGE_BRANCH_UUID = NULL

Deleting these rows fixed the issue.

@reda-alaoui
Copy link

reda-alaoui commented Oct 24, 2023

Closing as not-planned given there's no replication steps on this, and the check if there to prevent Sonarqube doing things that may further damage a project that already contains invalid data.

This issue occurs randomly with a CI client trying to retrieve the pull request data, just after the pull request analysis end.

On the CI side, the client executes the following steps:

  1. wait for the Sonarqube PR analysis task to end
  2. once the task has ended, the client tries to list the project pull requests

The last step sometime fails with an error 500, most of the time succeeds. I'd say 5% of failures.

Logs of the client side:

14:17:21  Waiting PT5S before re-checking SonarQube task 'AYthnVLGZBhuWkO_RLa4' status ...
14:17:26  SonarQube task 'AYthnVLGZBhuWkO_RLa4' is in progress.
14:17:26  Waiting PT5S before re-checking SonarQube task 'AYthnVLGZBhuWkO_RLa4' status ...
14:17:31  SonarQube task 'AYthnVLGZBhuWkO_RLa4' completed.
Error when executing always post condition:
Also:   org.jenkinsci.plugins.workflow.actions.ErrorAction$ErrorId: 462f1912-524b-40d4-a8c9-d2412ffc2e7b
me.redaalaoui.org.sonarqube.ws.client.HttpException: Error 500 on https://sonarqube.acme.dev/api/project_pull_requests/list?project=com.acme.project%3Aproject : {"errors":[{"msg":"An error has occurred. Please contact your administrator"}]}
	at me.redaalaoui.org.sonarqube.ws.client.BaseResponse.failIfNotSuccessful(BaseResponse.java:36)
	at me.redaalaoui.org.sonarqube.ws.client.BaseService.call(BaseService.java:52)
	at me.redaalaoui.org.sonarqube.ws.client.BaseService.call(BaseService.java:47)
	at me.redaalaoui.org.sonarqube.ws.client.projectpullrequests.ProjectPullRequestsService.list(ProjectPullRequestsService.java:65)
	at org.jenkinsci.plugins.sonargerrit.sonar.pull_request_analysis.PullRequestAnalysisTask.fetchIssues(PullRequestAnalysisTask.java:138)
	at org.jenkinsci.plugins.sonargerrit.sonar.pull_request_analysis.PullRequestAnalysisStrategy.analyse(PullRequestAnalysisStrategy.java:29)
	at org.jenkinsci.plugins.sonargerrit.sonar.Inspection.analyse(Inspection.java:78)

Logs of the Sonarqube side:

2023.10.24 14:18:13 ERROR web[AYmsYTBYF/Mc0HsECAr2][o.s.s.w.WebServiceEngine] Fail to process request http://sonarqube.acme.dev/api/project_pull_requests
/list?project=com.acme.project%3Aproject
java.lang.NullPointerException: Pull request data should be available for branch type PULL_REQUEST
        at java.base/java.util.Objects.requireNonNull(Objects.java:235)
        at com.github.mc1arke.sonarqube.plugin.server.pullrequest.ws.pullrequest.action.ListAction.addPullRequest(ListAction.java:123)
        at com.github.mc1arke.sonarqube.plugin.server.pullrequest.ws.pullrequest.action.ListAction.lambda$handleProjectRequest$2(ListAction.java:102)
        at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
        at com.github.mc1arke.sonarqube.plugin.server.pullrequest.ws.pullrequest.action.ListAction.handleProjectRequest(ListAction.java:102)
        at com.github.mc1arke.sonarqube.plugin.server.pullrequest.ws.pullrequest.action.ProjectWsAction.handle(ProjectWsAction.java:61)
        at org.sonar.server.ws.WebServiceEngine.execute(WebServiceEngine.java:111)

On the database side

sonarqube=> select * from project_branches where kee = '37625-10';
-[ RECORD 1 ]-----------------+---------------------------------------------------------------------------------------------------------------------------
uuid                          | AYtiNLl7ZBhuWkO_RLbl
project_uuid                  | AWOeaMUnRKTGso_RJvNe
kee                           | 37625-10
branch_type                   | PULL_REQUEST
merge_branch_uuid             | AWOeaMUnRKTGso_RJvNe
created_at                    | 1698159704492
updated_at                    | 1698160012494
pull_request_binary           | [redacted]
manual_baseline_analysis_uuid | 
exclude_from_purge            | f
need_issue_sync               | f

pull_request_binary is not null.

After a little while, the endpoint does not fail again since all other CI builds are green. Maybe there is a delay between the PR analysis availability and the pull_request_binary population?

reda-alaoui added a commit to jenkinsci/sonar-gerrit-plugin that referenced this issue Oct 24, 2023
This change tries to account for issue like the one described in
mc1arke/sonarqube-community-branch-plugin#759 (comment)
reda-alaoui added a commit to jenkinsci/sonar-gerrit-plugin that referenced this issue Oct 24, 2023
This change tries to account for issue like the one described in
mc1arke/sonarqube-community-branch-plugin#759 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants