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

Exception when analysing PR targeting long lived branch #4

Closed
mildis opened this issue Apr 1, 2019 · 13 comments
Closed

Exception when analysing PR targeting long lived branch #4

mildis opened this issue Apr 1, 2019 · 13 comments
Assignees
Labels
bug Something isn't working

Comments

@mildis
Copy link

mildis commented Apr 1, 2019

The following exception is raised when analysing a PR.
The master branch already exists for the project.

SonarScanner is started with parameters -Dsonar.pullrequest.branch=changes/19/14219/2 -Dsonar.pullrequest.key=14219

Any ideas ?

java.util.NoSuchElementException: No value present
	at java.util.Optional.get(Optional.java:135)
	at org.sonar.ce.task.projectanalysis.step.ValidateProjectStep.validateTargetBranch(ValidateProjectStep.java:94)
	at org.sonar.ce.task.projectanalysis.step.ValidateProjectStep.execute(ValidateProjectStep.java:77)
	at org.sonar.ce.task.step.ComputationStepExecutor.executeStep(ComputationStepExecutor.java:81)
	at org.sonar.ce.task.step.ComputationStepExecutor.executeSteps(ComputationStepExecutor.java:72)
	at org.sonar.ce.task.step.ComputationStepExecutor.execute(ComputationStepExecutor.java:59)
	at org.sonar.ce.task.projectanalysis.taskprocessor.ReportTaskProcessor.process(ReportTaskProcessor.java:81)
	at org.sonar.ce.taskprocessor.CeWorkerImpl$ExecuteTask.executeTask(CeWorkerImpl.java:207)
	at org.sonar.ce.taskprocessor.CeWorkerImpl$ExecuteTask.run(CeWorkerImpl.java:189)
	at org.sonar.ce.taskprocessor.CeWorkerImpl.findAndProcessTask(CeWorkerImpl.java:156)
	at org.sonar.ce.taskprocessor.CeWorkerImpl$TrackRunningState.get(CeWorkerImpl.java:131)
	at org.sonar.ce.taskprocessor.CeWorkerImpl.call(CeWorkerImpl.java:83)
	at org.sonar.ce.taskprocessor.CeWorkerImpl.call(CeWorkerImpl.java:51)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)
@mc1arke
Copy link
Owner

mc1arke commented Apr 2, 2019

To help with replicating this can you provide the following information:

  • Version of SonarQube
  • Version of Community Branch Plugin
  • Whether the current project pre-existed you installing the Community Branch Plugin

Are you also able to check if also providing -Dsonar.pullrequest.base=master in the scanner arguments causes the same error?

@mc1arke mc1arke self-assigned this Apr 2, 2019
@mc1arke mc1arke added the question Further information is requested label Apr 2, 2019
@mildis
Copy link
Author

mildis commented Apr 2, 2019

We are doing tests on SQ 7.7 with plugin version 1.0.1 as downloaded on the release tab.
The project existed before the plugin was installed.
We tried to do a full analysis again before doing a PR : no luck.
We completely deleted the project, did a full master analysis then a PR : no luck.

Forcing sonar.pullrequest.base fails too.

A successful POST is made to <server>/project/issues?id=<projectKey>&pullRequest=<pullrequest.key>&resolved=false but the exception is still thrown server-side.

From a DB point-of-view, the master branch exists as a long-lived branch.

| AWnczhQwkjhKxBBcn27m | AWnczhQwkjhKxBBcn27m | master | LONG        | NULL              | 1554187686965 | 1554187695247 | BRANCH   | NULL                | NULL                          |

@mc1arke mc1arke added bug Something isn't working and removed question Further information is requested labels Apr 2, 2019
mc1arke added a commit that referenced this issue Apr 2, 2019
A lookup is performed on the target branch of a pull request to ensure the branch exists, since SonarQube uses this as the base for collecting metrics on the Pull Request. However, the retrieved branch is then used incorrectly, with the UUID of the retrieved branch's target branch being returned as the target for the Pull Request, rather than the UUID of the retrieved branch. As long-lived branches that are generally targeted by Pull Requests will not have a target branch, this may result in a `NoSuchElementException` from SonarQube's Compute Engine when trying to use the non-existent UUID, or SonarQube showing the wrong branch as being targeted for a pull request and picking up new issues on the source branch incorrectly where a short-lived branch is targeted.

This change updates the generation of the pull request details to use the UUID of the retrieved target branch when creating Pull Request details, rather than the UUID of the target of the retrieved target branch.
@mc1arke
Copy link
Owner

mc1arke commented Apr 2, 2019

Could you try using unzipping and installing sonarqube-community-branch-plugin-1.1.0-SNAPSHOT.zip to see if this fixes your issue? It's built from the bug/issue4 branch which contains a proposed fix for the wrong branch being targeted in Pull Requests.

@mildis
Copy link
Author

mildis commented Apr 3, 2019

Same :

2019.04.03 09:01:10 INFO  ce[][o.s.c.t.CeWorkerImpl] Execute task | type=REPORT | pullRequest=14219 | id=AWniAGL4NvIeHJxeTbGU | submitter=cochin
2019.04.03 09:01:10 INFO  ce[AWniAGL4NvIeHJxeTbGU][o.s.c.t.s.ComputationStepExecutor] Extract report | status=SUCCESS | time=107ms
2019.04.03 09:01:10 INFO  ce[AWniAGL4NvIeHJxeTbGU][o.s.c.t.s.ComputationStepExecutor] Persist scanner context | status=SUCCESS | time=8ms
2019.04.03 09:01:10 INFO  ce[AWniAGL4NvIeHJxeTbGU][o.s.c.t.s.ComputationStepExecutor] Propagate analysis warnings from scanner report | status=SUCCESS | time=0ms
2019.04.03 09:01:10 INFO  ce[AWniAGL4NvIeHJxeTbGU][o.s.c.t.s.ComputationStepExecutor] Execute DB migrations for current project | status=SUCCESS | time=2ms
2019.04.03 09:01:10 INFO  ce[AWniAGL4NvIeHJxeTbGU][o.s.c.t.s.ComputationStepExecutor] Generate analysis UUID | status=SUCCESS | time=0ms
2019.04.03 09:01:10 INFO  ce[AWniAGL4NvIeHJxeTbGU][o.s.c.t.s.ComputationStepExecutor] Load analysis metadata | status=FAILED | time=4ms
2019.04.03 09:01:10 ERROR ce[AWniAGL4NvIeHJxeTbGU][o.s.c.t.s.ComputationStepExecutor] Execution of listener failed
java.lang.IllegalStateException: Missing project key
	at org.sonar.ce.task.projectanalysis.api.posttask.PostProjectAnalysisTasksExecutor.lambda$null$1(PostProjectAnalysisTasksExecutor.java:156)
	at java.util.Optional.orElseThrow(Optional.java:290)
	at org.sonar.ce.task.projectanalysis.api.posttask.PostProjectAnalysisTasksExecutor.lambda$createProject$3(PostProjectAnalysisTasksExecutor.java:156)
	at java.util.Optional.map(Optional.java:215)
	at org.sonar.ce.task.projectanalysis.api.posttask.PostProjectAnalysisTasksExecutor.createProject(PostProjectAnalysisTasksExecutor.java:154)
	at org.sonar.ce.task.projectanalysis.api.posttask.PostProjectAnalysisTasksExecutor.createProjectAnalysis(PostProjectAnalysisTasksExecutor.java:123)
	at org.sonar.ce.task.projectanalysis.api.posttask.PostProjectAnalysisTasksExecutor.finished(PostProjectAnalysisTasksExecutor.java:105)
	at org.sonar.ce.task.step.ComputationStepExecutor.executeListener(ComputationStepExecutor.java:91)
	at org.sonar.ce.task.step.ComputationStepExecutor.execute(ComputationStepExecutor.java:63)
	at org.sonar.ce.task.projectanalysis.taskprocessor.ReportTaskProcessor.process(ReportTaskProcessor.java:81)
	at org.sonar.ce.taskprocessor.CeWorkerImpl$ExecuteTask.executeTask(CeWorkerImpl.java:207)
	at org.sonar.ce.taskprocessor.CeWorkerImpl$ExecuteTask.run(CeWorkerImpl.java:189)
	at org.sonar.ce.taskprocessor.CeWorkerImpl.findAndProcessTask(CeWorkerImpl.java:156)
	at org.sonar.ce.taskprocessor.CeWorkerImpl$TrackRunningState.get(CeWorkerImpl.java:131)
	at org.sonar.ce.taskprocessor.CeWorkerImpl.call(CeWorkerImpl.java:83)
	at org.sonar.ce.taskprocessor.CeWorkerImpl.call(CeWorkerImpl.java:51)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)
2019.04.03 09:01:10 INFO  ce[AWniAGL4NvIeHJxeTbGU][o.s.c.t.CeWorkerImpl] Executed task | type=REPORT | pullRequest=14219 | id=AWniAGL4NvIeHJxeTbGU | submitter=cochin | status=FAILED | time=192ms

project_branches table is still empty of PR branches. Only the master branch is present. I tried to delete and make a full analysis but it still failed.

@mc1arke
Copy link
Owner

mc1arke commented Apr 3, 2019

That's a different stack-trace, so it looks like it has progressed beyond the initial failure.

Can you confirm what plugins you have installed in SonarQube? I believe my testing didn't face this issue since I may not have any Post Analysis Tasks requiring execution but the code would indicate that you have something that's performing additional activities (Pull Request decoration, report publishing etc).

Can you also confirm if this is still on a 'new' project that was created after the Branch Plugin was installed, and the Pull Request target branch does exist?

@mildis
Copy link
Author

mildis commented Apr 3, 2019

Here are all the plugins installed :

-rw-r--r-- 1 sonarqube sonarqube  1425513 May 20  2018 sonar-auth-oidc-plugin-1.0.4.jar
-rw-r--r-- 1 sonarqube sonarqube  4114423 Apr  1 12:40 sonar-csharp-plugin-7.12.0.8217.jar
-rw-r--r-- 1 sonarqube sonarqube  6031675 Dec 18 10:02 sonar-css-plugin-1.0.3.724.jar
-rw-r--r-- 1 sonarqube sonarqube  1551459 Jun 26  2018 sonar-flex-plugin-2.4.0.1222.jar
-rw-r--r-- 1 sonarqube sonarqube  3904078 Jun 26  2018 sonar-go-plugin-1.1.0.1612.jar
-rw-r--r-- 1 sonarqube sonarqube  1727846 Jan 22 09:13 sonar-html-plugin-3.1.0.1615.jar
-rw-r--r-- 1 sonarqube sonarqube    14629 Oct 24 17:17 sonar-jacoco-plugin-1.0.1.143.jar
-rw-r--r-- 1 sonarqube sonarqube  8283358 Mar 20 14:55 sonar-java-plugin-5.11.0.17289.jar
-rw-r--r-- 1 sonarqube sonarqube  6872614 Mar 20 14:55 sonar-javascript-plugin-5.1.1.7506.jar
-rw-r--r-- 1 sonarqube sonarqube  1899472 Apr 21  2017 sonar-jproperties-plugin-2.5.jar
-rw-r--r-- 1 sonarqube sonarqube  1876523 Apr 21  2017 sonar-json-plugin-2.2.jar
-rw-r--r-- 1 sonarqube sonarqube  7595999 Mar 20 14:55 sonar-kotlin-plugin-1.5.0.315.jar
-rw-r--r-- 1 sonarqube sonarqube    37897 Aug 13  2018 sonar-l10n-fr-plugin-1.15.1.jar
-rw-r--r-- 1 sonarqube sonarqube   300503 Aug  6  2017 sonar-ldap-plugin-2.2.0.608.jar
-rw-r--r-- 1 sonarqube sonarqube  4730004 Mar 20 14:55 sonar-php-plugin-3.0.0.4537.jar
-rw-r--r-- 1 sonarqube sonarqube  2753233 Mar 20 14:55 sonar-python-plugin-1.13.0.2922.jar
-rw-r--r-- 1 sonarqube sonarqube    34797 Apr  3 08:31 sonarqube-community-branch-plugin-1.1.0-SNAPSHOT.jar
-rw-r--r-- 1 sonarqube sonarqube 10036210 Mar 20 14:55 sonar-ruby-plugin-1.5.0.315.jar
-rw-r--r-- 1 sonarqube sonarqube  9202024 Mar 20 14:55 sonar-scala-plugin-1.5.0.315.jar
-rw-r--r-- 1 sonarqube sonarqube  2622236 Mar 20 14:55 sonar-scm-git-plugin-1.8.0.1574.jar
-rw-r--r-- 1 sonarqube sonarqube  7229293 Oct 29 09:19 sonar-scm-svn-plugin-1.9.0.1295.jar
-rw-r--r-- 1 sonarqube sonarqube  2239156 Jan 24 19:55 sonar-typescript-plugin-1.9.0.3766.jar
-rw-r--r-- 1 sonarqube sonarqube  3599280 Apr  1 12:40 sonar-vbnet-plugin-7.12.0.8217.jar
-rw-r--r-- 1 sonarqube sonarqube  2242738 Jan 17 20:12 sonar-xml-plugin-2.0.1.2020.jar

The project has been deleted this morning after the 1.1.0-SNAPSHOT was installed.
The very first analysis created the master branch (as confirmed by the epoch timestamps in the database)
The PR target branch (sonar.pullrequest.base) has been set to master and therefor exists.

@mc1arke
Copy link
Owner

mc1arke commented Apr 6, 2019

I'm unable to replicate your second exception on a clean SonarQube 7.7 installation running a build of this plugin containing the currently proposed fixes for #4 and #6 and a dummy Post Post Analysis Task executing on every scan. As the 2 open issues are both blockers to performing Pull Request analysis and have fixes identified, I'm going to merge the current branches and release the plugin and close the issues as having their initial causes resolved.

If you continue to face issues after upgrading to the new plugin then please raise a further issue that details each problem and any steps to replicate it.

@mc1arke mc1arke changed the title Exception when analysing PR Exception when analysing PR targeting long lived branch Apr 6, 2019
@mildis
Copy link
Author

mildis commented Apr 6, 2019

Would you mind posting the commands you’re using for full and PR analysis ? We may miss useful arguments.

@mildis
Copy link
Author

mildis commented Apr 8, 2019

Finally got a PR but ran into #6 (got a String but try to unmarshall as long)

@mildis mildis closed this as completed Apr 8, 2019
@mc1arke
Copy link
Owner

mc1arke commented Apr 8, 2019

What did you have to change to get it to work (or what would I need to do to replicate the failure)?

@mildis
Copy link
Author

mildis commented Apr 8, 2019

Don"t really know : we did another clean up (full erasure) of the project in SQ then ran an analysis with a PR name with another name than just digits (we used to set sonar.pullrequest.key to a digits-only key)

@mildis
Copy link
Author

mildis commented Apr 8, 2019

And we dropped the whole ce_activity history table.

mc1arke added a commit that referenced this issue Apr 8, 2019
A lookup is performed on the target branch of a pull request to ensure the branch exists, since SonarQube uses this as the base for collecting metrics on the Pull Request. However, the retrieved branch is then used incorrectly, with the UUID of the retrieved branch's target branch being returned as the target for the Pull Request, rather than the UUID of the retrieved branch. As long-lived branches that are generally targeted by Pull Requests will not have a target branch, this may result in a `NoSuchElementException` from SonarQube's Compute Engine when trying to use the non-existent UUID, or SonarQube showing the wrong branch as being targeted for a pull request and picking up new issues on the source branch incorrectly where a short-lived branch is targeted.

This change updates the generation of the pull request details to use the UUID of the retrieved target branch when creating Pull Request details, rather than the UUID of the target of the retrieved target branch.
@mc1arke
Copy link
Owner

mc1arke commented Apr 8, 2019

Released in 1.0.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants