]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-21259 Fix code issues
authorEric Giffon <eric.giffon@sonarsource.com>
Fri, 22 Dec 2023 13:47:59 +0000 (14:47 +0100)
committersonartech <sonartech@sonarsource.com>
Wed, 17 Jan 2024 20:02:44 +0000 (20:02 +0000)
server/sonar-webserver-es/src/main/java/org/sonar/server/issue/index/IssueQueryFactory.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/SearchActionIT.java

index 1222629845fdfa170519e90419b756d3da8f68b3..8a982b76466b274951d68d60110858e3590a0c67 100644 (file)
@@ -41,6 +41,7 @@ import java.util.Set;
 import java.util.stream.Collectors;
 import javax.annotation.Nullable;
 import org.apache.commons.lang.BooleanUtils;
+import org.apache.commons.lang.StringUtils;
 import org.jetbrains.annotations.NotNull;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -179,18 +180,19 @@ public class IssueQueryFactory {
     if (request.getFixedInPullRequest() != null) {
       issueKeys = getIssuesFixedByPullRequest(dbSession, request);
     }
-    if (request.getIssues() != null && !request.getIssues().isEmpty()) {
+    List<String> requestIssues = request.getIssues();
+    if (requestIssues != null && !requestIssues.isEmpty()) {
       if (issueKeys == null) {
         issueKeys = new ArrayList<>();
       }
-      issueKeys.addAll(request.getIssues());
+      issueKeys.addAll(requestIssues);
     }
-
     return issueKeys;
   }
 
   private Collection<String> getIssuesFixedByPullRequest(DbSession dbSession, SearchRequest request) {
     String fixedInPullRequest = request.getFixedInPullRequest();
+    checkArgument(StringUtils.isNotBlank(fixedInPullRequest), "Parameter '%s' is empty", PARAM_FIXED_IN_PULL_REQUEST);
     List<String> componentKeys = request.getComponentKeys();
     if (componentKeys == null || componentKeys.size() != 1) {
       throw new IllegalArgumentException("Exactly one project needs to be provided in the " +
@@ -200,14 +202,15 @@ public class IssueQueryFactory {
     ProjectDto projectDto = dbClient.projectDao().selectProjectByKey(dbSession, projectKey)
       .orElseThrow(() -> new IllegalArgumentException("Project with key '" + projectKey + "' does not exist"));
     BranchDto pullRequest = dbClient.branchDao().selectByPullRequestKey(dbSession, projectDto.getUuid(), fixedInPullRequest)
-      .orElseThrow(() -> new IllegalArgumentException("Pull request with key '" + fixedInPullRequest + "' does not exist for project " +
+      .orElseThrow(() -> new IllegalArgumentException("Pull request with key '" + fixedInPullRequest + "' does not exist for project " +
         projectKey));
 
-    if (request.getBranch() != null) {
-      BranchDto targetBranch = dbClient.branchDao().selectByBranchKey(dbSession, projectDto.getUuid(), request.getBranch())
-        .orElseThrow(() -> new IllegalArgumentException("Branch with key '" + request.getBranch() + "' does not exist"));
+    String branch = request.getBranch();
+    if (branch != null) {
+      BranchDto targetBranch = dbClient.branchDao().selectByBranchKey(dbSession, projectDto.getUuid(), branch)
+        .orElseThrow(() -> new IllegalArgumentException("Branch with key '" + branch + "' does not exist"));
       if (!Objects.equals(targetBranch.getUuid(), pullRequest.getMergeBranchUuid())) {
-        throw new IllegalArgumentException("Pull request with key '" + fixedInPullRequest + "' does not target branch '" + request.getBranch() + "'");
+        throw new IllegalArgumentException("Pull request with key '" + fixedInPullRequest + "' does not target branch '" + branch + "'");
       }
     }
     return dbClient.issueFixedDao().selectByPullRequest(dbSession, pullRequest.getUuid())
@@ -216,7 +219,6 @@ public class IssueQueryFactory {
       .collect(Collectors.toSet());
   }
 
-
   private static Optional<ZoneId> parseTimeZone(@Nullable String timeZone) {
     if (timeZone == null) {
       return Optional.empty();
index e9fc5f67010f07bdf035f3b81788915ea404de87..57bf527f6b83491f8464aa9923527d5aee4ed7e1 100644 (file)
@@ -2228,7 +2228,7 @@ public class SearchActionIT {
 
     assertThatThrownBy(request::execute)
       .isInstanceOf(IllegalArgumentException.class)
-      .hasMessage("Pull request with key 'wrongPullRequest' does not exist for project " + project.projectKey());
+      .hasMessage("Pull request with key 'wrongPullRequest' does not exist for project " + project.projectKey());
   }
 
   @Test