Skip to content

Commit 4c830bc

Browse files
authored
Fix NullPointerException when autoboxing (#460)
1 parent 45a1ef5 commit 4c830bc

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabMergeRequestCommentTrigger.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,10 @@ public void isMatch() {
5252
if (!sourceContext.mrCommentTriggerEnabled()) {
5353
continue;
5454
}
55-
if (gitLabSCMSource.getProjectId()
56-
== getPayload().getMergeRequest().getTargetProjectId()
55+
Long projectId = gitLabSCMSource.getProjectId();
56+
if (projectId != null
57+
&& projectId.equals(
58+
getPayload().getMergeRequest().getTargetProjectId())
5759
&& isTrustedMember(gitLabSCMSource, sourceContext.getOnlyTrustedMembersCanTrigger())) {
5860
for (Job<?, ?> job : owner.getAllJobs()) {
5961
if (MultiBranchProject.class.isAssignableFrom(

src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabSCMSource.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -237,12 +237,12 @@ public HashMap<String, AccessLevel> getMembers() {
237237
return members;
238238
}
239239

240-
public long getProjectId() {
240+
public Long getProjectId() {
241241
return projectId;
242242
}
243243

244244
@DataBoundSetter
245-
public void setProjectId(long projectId) {
245+
public void setProjectId(Long projectId) {
246246
this.projectId = projectId;
247247
}
248248

src/test/java/io/jenkins/plugins/gitlabbranchsource/GitLabSCMSourceDeserializationTest.java

+22
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.jenkins.plugins.gitlabbranchsource;
22

3+
import static org.junit.Assert.assertEquals;
34
import static org.junit.Assert.assertNotNull;
45

56
import java.lang.reflect.Field;
@@ -43,4 +44,25 @@ public void afterRestartingJenkinsTransientFieldsAreNotNull() throws Exception {
4344
assertNotNull(mergeRequestContributorCache.get(source));
4445
});
4546
}
47+
48+
@Test
49+
public void projectIdSurvivesConfigRoundtrip() {
50+
plan.then(j -> {
51+
GitLabSCMSourceBuilder sb =
52+
new GitLabSCMSourceBuilder(SOURCE_ID, "server", "creds", "po", "group/project", "project");
53+
WorkflowMultiBranchProject project = j.createProject(WorkflowMultiBranchProject.class, PROJECT_NAME);
54+
GitLabSCMSource source = sb.build();
55+
project.getSourcesList().add(new BranchSource(source));
56+
long p = 42;
57+
source.setProjectId(p);
58+
j.configRoundtrip(project);
59+
60+
WorkflowMultiBranchProject item =
61+
j.jenkins.getItemByFullName(PROJECT_NAME, WorkflowMultiBranchProject.class);
62+
assertNotNull(item);
63+
GitLabSCMSource scmSource = (GitLabSCMSource) item.getSCMSource(SOURCE_ID);
64+
assertNotNull(scmSource);
65+
assertEquals(Long.valueOf(p), scmSource.getProjectId());
66+
});
67+
}
4668
}

0 commit comments

Comments
 (0)