]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-15211 Fix NPE in case performing operation on an issue which rule has been...
authorJacek <jacek.poreda@sonarsource.com>
Mon, 13 Sep 2021 15:16:45 +0000 (17:16 +0200)
committersonartech <sonartech@sonarsource.com>
Tue, 14 Sep 2021 20:03:24 +0000 (20:03 +0000)
server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SearchResponseLoader.java

index 4fb9b30e3a63b597da21d67410fd5be00b2abedf..9d2bc412693f3f0f7a002b2a9a7463aacee4b1f6 100644 (file)
@@ -28,6 +28,7 @@ import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Objects;
+import java.util.Optional;
 import java.util.Set;
 import java.util.stream.Collectors;
 import javax.annotation.Nullable;
@@ -168,7 +169,8 @@ public class SearchResponseLoader {
     List<RuleDefinitionDto> preloadedRules = firstNonNull(preloadedResponseData.getRules(), emptyList());
     result.addRules(preloadedRules);
     Set<String> ruleUuidsToLoad = collector.getRuleUuids();
-    ruleUuidsToLoad.removeAll(preloadedRules.stream().map(RuleDefinitionDto::getUuid).collect(toList(preloadedRules.size())));
+    preloadedRules.stream().map(RuleDefinitionDto::getUuid).collect(toList(preloadedRules.size()))
+        .forEach(ruleUuidsToLoad::remove);
 
     List<RuleDefinitionDto> rules = dbClient.ruleDao().selectDefinitionByUuids(dbSession, ruleUuidsToLoad);
 
@@ -262,7 +264,7 @@ public class SearchResponseLoader {
       for (IssueDto issue : issues) {
         componentUuids.add(issue.getComponentUuid());
         projectUuids.add(issue.getProjectUuid());
-        ruleUuids.add(issue.getRuleUuid());
+        Optional.ofNullable(issue.getRuleUuid()).ifPresent(ruleUuids::add);
         String issueAssigneeUuid = issue.getAssigneeUuid();
         if (issueAssigneeUuid != null) {
           userUuids.add(issueAssigneeUuid);
@@ -359,8 +361,7 @@ public class SearchResponseLoader {
     rules.stream().forEach(r -> {
       if (r.isAdHoc()) {
         String adHocName = adHocRulesMetadata.stream()
-          .filter(m -> m.getRuleUuid().equals(r.getUuid())).findFirst().
-            map(RuleMetadataDto::getAdHocName)
+          .filter(m -> m.getRuleUuid().equals(r.getUuid())).findFirst().map(RuleMetadataDto::getAdHocName)
           .orElse(null);
         r.setName(adHocName);
       }