Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-57775

NullPointerException when scan bitbucket multi-branch

    Details

    • Similar Issues:

      Description

      This will happen when there are some PRs that don't have any destination commits.
      This will happen when a PR is open and that PR's source or destination branch does not exist.

       

      Ref:
      https://github.com/jenkinsci/bitbucket-branch-source-plugin

        Attachments

          Issue Links

            Activity

            Hide
            michelzanini Michel Zanini added a comment -

            This bug is a duplication of https://issues.jenkins-ci.org/browse/JENKINS-56309.
            I am also experiencing this and will report steps on how to reproduce.

            Show
            michelzanini Michel Zanini added a comment - This bug is a duplication of https://issues.jenkins-ci.org/browse/JENKINS-56309 . I am also experiencing this and will report steps on how to reproduce.
            Hide
            michelzanini Michel Zanini added a comment -

            To reproduce the issue above, on Bitbucket Cloud, follow the steps:

            • Create a new branch, here we will create a branch called develop.
            • No need to do any commits to it, create another branch from develop, we can call it my_changes
            • Commit something to my_changes
            • Create a PR from my_changes to ** develop**
            • Go to Jenkins and see that there are builds for both branches and the PR
            • Now open Bitbucket Cloud and delete the develop - don't decline the PR (leave it open)
            • Now when opening the PR there will be zero commits on the PR (the target branch no longer exists)
            • Go back to Jenkins multi-branch pipeline and press Scan Multibranch Pipeline Log
            • **When the plugin is canning the PRs it will fail with the exception reported here

            The cause:

            The API call done to get all pull requests is made from:

             

            BitbucketCloudApiClient.getPullRequests()
            

            In the this call, the JSON is parsed to:

             

             

            -> BitbucketPullRequests
               -> List<BitbucketPullRequestValue> values;
                    -> BitbucketPullRequestValueDestination destination;

            And BitbucketPullRequestValueDestination class has this constructor: 

             

             

            @JsonCreator
            public BitbucketPullRequestValueDestination(@NonNull @JsonProperty("repository") BitbucketCloudRepository repository,
                                                        @NonNull @JsonProperty("branch") BitbucketCloudBranch branch,
                                                        @NonNull @JsonProperty("commit") BitbucketCloudCommit commit) {
                this.repository = repository;
                this.branch = branch;
                this.commit = commit;
            
                // redound available the informations into impl objects
                this.branch.setRawNode(commit.getHash());
            }
            

            You can see here:

             

             

            @NonNull @JsonProperty("commit") BitbucketCloudCommit commit
            

            The @NotNull here is what is causing the exception. The JSON is returning null for commit. See:

             

             

            ...
                        "destination": {
                            "commit": null,
                            "repository": {
                                "links": {
                                    ...
                                },
                                "type": "repository",
                                "name": "my-demo-project",
                                "full_name": "my/my-demo-project",
                                "uuid": "{asdsdsd-5b91-44e5-9f76-af5612323123}"
                            },
                            "branch": {
                                "name": "develop"
                            }
                        },
            ...

            I could create a PR to make BitbucketCloudCommit commit nullable.

            But, this field is used in 5 different places, a few of them with a null check.

            It is more work then just making it nullable, I think we might want to filter out PRs with no destination commit and remove then from Jenkins multi-branch jobs...

            Joseph Petersen (old) - if you could fix this it would be great.

             

            -> Workaround is to manually decline the PR on Bitbucket.

             

             

            Show
            michelzanini Michel Zanini added a comment - To reproduce the issue above, on Bitbucket Cloud, follow the steps: Create a new branch, here we will create a branch called develop . No need to do any commits to it, create another branch from develop, we can call it my_changes Commit something to  my_changes Create a PR from  my_changes to **  develop ** Go to Jenkins and see that there are builds for both branches and the PR Now open Bitbucket Cloud and delete the  develop  - don't decline the PR (leave it open) Now when opening the PR there will be zero commits on the PR (the target branch no longer exists) Go back to Jenkins multi-branch pipeline and press  Scan Multibranch Pipeline Log **When the plugin is canning the PRs it will fail with the exception reported here The cause: The API call done to get all pull requests is made from:   BitbucketCloudApiClient.getPullRequests() In the this call, the JSON is parsed to:     -> BitbucketPullRequests -> List<BitbucketPullRequestValue> values; -> BitbucketPullRequestValueDestination destination; And BitbucketPullRequestValueDestination class has this constructor:      @JsonCreator public BitbucketPullRequestValueDestination(@NonNull @JsonProperty( "repository" ) BitbucketCloudRepository repository, @NonNull @JsonProperty( "branch" ) BitbucketCloudBranch branch, @NonNull @JsonProperty( "commit" ) BitbucketCloudCommit commit) { this .repository = repository; this .branch = branch; this .commit = commit; // redound available the informations into impl objects this .branch.setRawNode(commit.getHash()); } You can see here:     @NonNull @JsonProperty( "commit" ) BitbucketCloudCommit commit The @NotNull  here is what is causing the exception. The JSON is returning null for commit. See:     ... "destination" : { "commit" : null , "repository" : { "links" : { ... }, "type" : "repository" , "name" : "my-demo-project" , "full_name" : "my/my-demo-project" , "uuid" : "{asdsdsd-5b91-44e5-9f76-af5612323123}" }, "branch" : { "name" : "develop" } }, ... I could create a PR to make  BitbucketCloudCommit commit nullable. But, this field is used in 5 different places, a few of them with a null check. It is more work then just making it nullable , I think we might want to filter out PRs with no destination commit and remove then from Jenkins multi-branch jobs... Joseph Petersen (old) - if you could fix this it would be great.   -> Workaround is to manually decline the PR on Bitbucket.    
            Hide
            tim_dat Tim Fagergren added a comment -

            It seems that at one point there was an intention to allow the PR's original destination to no longer exist: https://github.com/jenkinsci/bitbucket-branch-source-plugin/blob/a18e9d41dca08652d2bb2ce71fbf113e9ae5fb5a/src/main/java/com/cloudbees/jenkins/plugins/bitbucket/client/pullrequest/BitbucketPullRequestValueDestination.java#L52

            But this functionality doesn't seem to be working as expected.

            Show
            tim_dat Tim Fagergren added a comment - It seems that at one point there was an intention to allow the PR's original destination to no longer exist: https://github.com/jenkinsci/bitbucket-branch-source-plugin/blob/a18e9d41dca08652d2bb2ce71fbf113e9ae5fb5a/src/main/java/com/cloudbees/jenkins/plugins/bitbucket/client/pullrequest/BitbucketPullRequestValueDestination.java#L52 But this functionality doesn't seem to be working as expected.
            Hide
            rzhou Ronnie Zhou added a comment -

            This should be fixed already in Bitbucket Branch Source 2.8.0 https://github.com/jenkinsci/bitbucket-branch-source-plugin/pull/283

            Show
            rzhou Ronnie Zhou added a comment - This should be fixed already in Bitbucket Branch Source 2.8.0  https://github.com/jenkinsci/bitbucket-branch-source-plugin/pull/283
            Hide
            allan_burdajewicz Allan BURDAJEWICZ added a comment - - edited

            I can still reproduce the problem with 2.8.0. The payload (checked from Bitbucket Cloud) shows that actually the commit may be null, not the branch, if the destination branch is deleted. The fix provided in 2.8.0 check for nullity of the branch.

            com.cloudbees.jenkins.plugins.bitbucket.client.pullrequest.BitbucketPullRequestValueDestination.<init>(BitbucketPullRequestValueDestination.java:55)
            

            Similar problems may happen with the Source too (PR from deleted forks). Created https://issues.jenkins-ci.org/browse/JENKINS-62780 for that other scenario.

            Show
            allan_burdajewicz Allan BURDAJEWICZ added a comment - - edited I can still reproduce the problem with 2.8.0. The payload (checked from Bitbucket Cloud) shows that actually the commit may be null, not the branch , if the destination branch is deleted. The fix provided in 2.8.0 check for nullity of the branch . com.cloudbees.jenkins.plugins.bitbucket.client.pullrequest.BitbucketPullRequestValueDestination.<init>(BitbucketPullRequestValueDestination.java:55) Similar problems may happen with the Source too (PR from deleted forks). Created https://issues.jenkins-ci.org/browse/JENKINS-62780 for that other scenario.
            Hide
            allan_burdajewicz Allan BURDAJEWICZ added a comment -

            Should be fixed by https://issues.jenkins-ci.org/browse/JENKINS-62780 in version 2.9.0

            Show
            allan_burdajewicz Allan BURDAJEWICZ added a comment - Should be fixed by https://issues.jenkins-ci.org/browse/JENKINS-62780 in version 2.9.0

              People

              • Assignee:
                surenpi Rick
                Reporter:
                surenpi Rick
              • Votes:
                1 Vote for this issue
                Watchers:
                6 Start watching this issue

                Dates

                • Created:
                  Updated: