diff options
author | Duarte Meneses <duarte.meneses@sonarsource.com> | 2021-09-23 13:40:48 -0500 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2021-09-24 20:03:10 +0000 |
commit | 5377194709960576b1367a220c6ba20ce6f41ef0 (patch) | |
tree | f025ed253351eaa7be06da629a9ba4d7c3a8816f /sonar-scanner-engine/src | |
parent | 4129719fc2f969fb785b64b3d7ed7291281feb85 (diff) | |
download | sonarqube-5377194709960576b1367a220c6ba20ce6f41ef0.tar.gz sonarqube-5377194709960576b1367a220c6ba20ce6f41ef0.zip |
SONAR-15424 Compute Engine fails with NPE when analysing PR without main branch
Diffstat (limited to 'sonar-scanner-engine/src')
-rw-r--r-- | sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/branch/ProjectBranches.java | 7 | ||||
-rw-r--r-- | sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/branch/ProjectBranchesTest.java | 1 |
2 files changed, 7 insertions, 1 deletions
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/branch/ProjectBranches.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/branch/ProjectBranches.java index 2c49da58963..9f53d9ad8a2 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/branch/ProjectBranches.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/branch/ProjectBranches.java @@ -22,6 +22,7 @@ package org.sonar.scanner.scan.branch; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Objects; import javax.annotation.CheckForNull; import javax.annotation.concurrent.Immutable; @@ -30,6 +31,9 @@ import javax.annotation.concurrent.Immutable; */ @Immutable public class ProjectBranches { + // matches server-side default when creating a project. See BranchDto#DEFAULT_MAIN_BRANCH_NAME + private static final String DEFAULT_MAIN_BRANCH_NAME = "master"; + private final Map<String, BranchInfo> branches; private final String defaultBranchName; @@ -43,7 +47,8 @@ public class ProjectBranches { mainBranchName = branchName; } } - this.defaultBranchName = mainBranchName; + + this.defaultBranchName = Objects.requireNonNullElse(mainBranchName, DEFAULT_MAIN_BRANCH_NAME); } @CheckForNull diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/branch/ProjectBranchesTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/branch/ProjectBranchesTest.java index d9f07a3df16..42daac13391 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/branch/ProjectBranchesTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/branch/ProjectBranchesTest.java @@ -70,5 +70,6 @@ public class ProjectBranchesTest { public void isEmpty() { assertThat(underTest.isEmpty()).isFalse(); assertThat(new ProjectBranches(Collections.emptyList()).isEmpty()).isTrue(); + assertThat(new ProjectBranches(Collections.emptyList()).defaultBranchName()).isEqualTo("master"); } } |