]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-10217 Fix 500 error when branch is incorrect
authorEric Hartmann <hartmann.eric@gmail.com>
Fri, 29 Dec 2017 09:16:55 +0000 (10:16 +0100)
committerEric Hartmann <hartmann.eric@gmail.Com>
Fri, 29 Dec 2017 10:29:03 +0000 (11:29 +0100)
server/sonar-server/src/main/java/org/sonar/server/issue/IssueQueryFactory.java
server/sonar-server/src/test/java/org/sonar/server/issue/ws/SearchActionTest.java

index 63974471ac085665544e285b88f24eba1d25159d..1c1c8024b482db0fdda7bd0448d202e6e6b45461 100644 (file)
@@ -394,6 +394,6 @@ public class IssueQueryFactory {
 
   private static void setBranch(IssueQuery.Builder builder, ComponentDto component, @Nullable String branch) {
     builder.branchUuid(branch == null ? null : component.projectUuid());
-    builder.mainBranch(branch == null || !branch.equals(component.getBranch()));
+    builder.mainBranch(branch == null || component.equals(UNKNOWN_COMPONENT) || !branch.equals(component.getBranch()));
   }
 }
index c8e3753999c3bbbcf94efb99638f0cdd4f5e4033..591b68c2886bc524e625892342b936494ab41e88 100644 (file)
@@ -151,6 +151,19 @@ public class SearchActionTest {
       "Portfolios are not supported. If this parameter is set, 'projects' must not be set.");
   }
 
+  //SONAR-10217
+  @Test
+  public void empty_search_with_unknown_branch() throws Exception {
+    TestResponse result = ws.newRequest()
+      .setParam("onComponentOnly", "true")
+      .setParam("componentKeys", "foo")
+      .setParam("branch", "bar")
+      .execute();
+
+    assertThat(result).isNotNull();
+    result.assertJson(this.getClass(), "empty_result.json");
+  }
+
   @Test
   public void empty_search() throws Exception {
     TestResponse result = ws.newRequest()