From 652bcc1cd8f6cb2d6281694a74300ef3b24fbc11 Mon Sep 17 00:00:00 2001 From: Eric Hartmann Date: Fri, 29 Dec 2017 10:16:55 +0100 Subject: [PATCH] SONAR-10217 Fix 500 error when branch is incorrect --- .../org/sonar/server/issue/IssueQueryFactory.java | 2 +- .../org/sonar/server/issue/ws/SearchActionTest.java | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/IssueQueryFactory.java b/server/sonar-server/src/main/java/org/sonar/server/issue/IssueQueryFactory.java index 63974471ac0..1c1c8024b48 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/issue/IssueQueryFactory.java +++ b/server/sonar-server/src/main/java/org/sonar/server/issue/IssueQueryFactory.java @@ -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())); } } diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/ws/SearchActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/ws/SearchActionTest.java index c8e3753999c..591b68c2886 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/ws/SearchActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/issue/ws/SearchActionTest.java @@ -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() -- 2.39.5