From c559b917c44db84f181c034c9cc204982ee9077a Mon Sep 17 00:00:00 2001 From: Jacek Date: Mon, 13 Sep 2021 17:16:45 +0200 Subject: [PATCH] SONAR-15211 Fix NPE in case performing operation on an issue which rule has been REMOVED --- .../org/sonar/server/issue/ws/SearchResponseLoader.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SearchResponseLoader.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SearchResponseLoader.java index 4fb9b30e3a6..9d2bc412693 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SearchResponseLoader.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SearchResponseLoader.java @@ -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 preloadedRules = firstNonNull(preloadedResponseData.getRules(), emptyList()); result.addRules(preloadedRules); Set 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 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); } -- 2.39.5