Skip to content

Fix JENKINS-71955 NullPointerException because getMergeRequestsEnabled is null#456

Merged
jetersen merged 4 commits into
jenkinsci:masterfrom
pbaumard:bugfix/JENKINS-71955
Nov 8, 2024
Merged

Fix JENKINS-71955 NullPointerException because getMergeRequestsEnabled is null#456
jetersen merged 4 commits into
jenkinsci:masterfrom
pbaumard:bugfix/JENKINS-71955

Conversation

@pbaumard
Copy link
Copy Markdown
Contributor

@pbaumard pbaumard commented Oct 29, 2024

Fix https://issues.jenkins.io/browse/JENKINS-71955

NullPointerException: Cannot invoke "java.lang.Boolean.booleanValue()" because the return value of "org.gitlab4j.api.models.Project.getMergeRequestsEnabled()" is null

This is an alternative to #406 since this PR really fixes the NPE.

Note that the current title of JENKINS-71955 "GitLab branch source scan fails with null pointer exception if credentials are not provided" is misleading since the NPE also occurs when credentials are provided.

A null getMergeRequestsEnabled seems to be a very common situation, and I cannot find any workaround for this bug in our current Gitlab version (17.5).

According to https://github.com/gitlab4j/gitlab4j-api/blob/fe96001fd18d9411f5b4fbbeeca2377bb3791864/src/main/java/org/gitlab4j/api/ProjectApi.java#L1195

mergeRequestsEnabled Whether Merge Requests should be enabled, otherwise null indicates to use GitLab default

And according to https://docs.gitlab.com/ee/api/projects.html#create-a-project

Attribute | Type | Required | Description
merge_requests_enabled | boolean | No | (Deprecated) Enable merge requests for this project. Use merge_requests_access_level instead.

Testing done

Added GitLabSCMSourceTest.java

Submitter checklist

  • Make sure you are opening from a topic/feature/bugfix branch (right side) and not your main branch!
  • Ensure that the pull request title represents the desired changelog entry
  • Please describe what you did
  • Link to relevant issues in GitHub or Jira
  • Link to relevant pull requests, esp. upstream and downstream changes
  • Ensure you have provided tests - that demonstrates feature works or fixes the issue

NullPointerException: Cannot invoke "java.lang.Boolean.booleanValue()" because the return value of "org.gitlab4j.api.models.Project.getMergeRequestsEnabled()" is null
@pbaumard pbaumard requested a review from jetersen as a code owner October 29, 2024 16:35
private static final String SOURCE_ID = "id";

@Rule
public final RestartableJenkinsRule plan = new RestartableJenkinsRule();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any particular reason to use RestartableJenkinsRule here over plain JenkinsRule?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No particular reason. I changed the test to use JenkinsRule.

@basil basil requested a review from a team November 8, 2024 19:19
@basil basil added the bug Something isn't working label Nov 8, 2024
@jetersen jetersen merged commit 45a1ef5 into jenkinsci:master Nov 8, 2024
@basil
Copy link
Copy Markdown
Member

basil commented Nov 21, 2024

Caused #460

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

Successfully merging this pull request may close these issues.

3 participants