From b6cb156530b5012f589d097fbbe84b855391accc Mon Sep 17 00:00:00 2001 From: Zipeng WU Date: Thu, 12 Jan 2023 15:07:29 +0100 Subject: [PATCH] [NO-JIRA] explicitly declare toList collector mutable or not --- .../main/java/org/sonar/ce/queue/CeQueueImpl.java | 2 +- .../TokenExpirationNotificationSender.java | 2 +- .../server/issue/index/AsyncIssueIndexingImpl.java | 3 ++- .../org/sonar/server/issue/index/IssueIndex.java | 5 +++-- .../java/org/sonar/server/setting/ws/Setting.java | 14 ++++++-------- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/server/sonar-ce-common/src/main/java/org/sonar/ce/queue/CeQueueImpl.java b/server/sonar-ce-common/src/main/java/org/sonar/ce/queue/CeQueueImpl.java index fe7fdd6179a..b124b509c02 100644 --- a/server/sonar-ce-common/src/main/java/org/sonar/ce/queue/CeQueueImpl.java +++ b/server/sonar-ce-common/src/main/java/org/sonar/ce/queue/CeQueueImpl.java @@ -138,7 +138,7 @@ public class CeQueueImpl implements CeQueue { List taskDtos = submissions.stream() .filter(filterBySubmitOptions(options, submissions, dbSession)) .map(submission -> addToQueueInDb(dbSession, submission)) - .collect(Collectors.toList()); + .toList(); List tasks = loadTasks(dbSession, taskDtos); dbSession.commit(); return tasks; diff --git a/server/sonar-webserver-auth/src/main/java/org/sonar/server/usertoken/notification/TokenExpirationNotificationSender.java b/server/sonar-webserver-auth/src/main/java/org/sonar/server/usertoken/notification/TokenExpirationNotificationSender.java index c5005990651..d331d3c477b 100644 --- a/server/sonar-webserver-auth/src/main/java/org/sonar/server/usertoken/notification/TokenExpirationNotificationSender.java +++ b/server/sonar-webserver-auth/src/main/java/org/sonar/server/usertoken/notification/TokenExpirationNotificationSender.java @@ -46,7 +46,7 @@ public class TokenExpirationNotificationSender { try (var dbSession = dbClient.openSession(false)) { var expiringTokens = dbClient.userTokenDao().selectTokensExpiredInDays(dbSession, 7); var expiredTokens = dbClient.userTokenDao().selectTokensExpiredInDays(dbSession, 0); - var tokensToNotify = Stream.concat(expiringTokens.stream(), expiredTokens.stream()).collect(Collectors.toList()); + var tokensToNotify = Stream.concat(expiringTokens.stream(), expiredTokens.stream()).toList(); var usersToNotify = tokensToNotify.stream().map(UserTokenDto::getUserUuid).collect(Collectors.toSet()); Map userUuidToEmail = dbClient.userDao().selectByUuids(dbSession, usersToNotify).stream() .collect(Collectors.toMap(UserDto::getUuid, UserDto::getEmail)); diff --git a/server/sonar-webserver-core/src/main/java/org/sonar/server/issue/index/AsyncIssueIndexingImpl.java b/server/sonar-webserver-core/src/main/java/org/sonar/server/issue/index/AsyncIssueIndexingImpl.java index a0a4b8f0206..8918d48bd2a 100644 --- a/server/sonar-webserver-core/src/main/java/org/sonar/server/issue/index/AsyncIssueIndexingImpl.java +++ b/server/sonar-webserver-core/src/main/java/org/sonar/server/issue/index/AsyncIssueIndexingImpl.java @@ -41,6 +41,7 @@ import org.sonar.db.component.BranchDto; import org.sonar.db.component.BranchType; import org.sonar.db.component.SnapshotDto; +import static java.util.stream.Collectors.toCollection; import static org.sonar.db.ce.CeTaskCharacteristicDto.BRANCH_KEY; import static org.sonar.db.ce.CeTaskCharacteristicDto.BRANCH_TYPE_KEY; import static org.sonar.db.ce.CeTaskCharacteristicDto.PULL_REQUEST; @@ -75,7 +76,7 @@ public class AsyncIssueIndexingImpl implements AsyncIssueIndexing { return; } - List projectUuids = branchInNeedOfIssueSync.stream().map(BranchDto::getProjectUuid).distinct().collect(Collectors.toList()); + List projectUuids = branchInNeedOfIssueSync.stream().map(BranchDto::getProjectUuid).distinct().collect(toCollection(ArrayList::new)); LOG.info("{} projects found in need of issue sync.", projectUuids.size()); sortProjectUuids(dbSession, projectUuids); diff --git a/server/sonar-webserver-es/src/main/java/org/sonar/server/issue/index/IssueIndex.java b/server/sonar-webserver-es/src/main/java/org/sonar/server/issue/index/IssueIndex.java index 0eddf3ffe48..ab823443523 100644 --- a/server/sonar-webserver-es/src/main/java/org/sonar/server/issue/index/IssueIndex.java +++ b/server/sonar-webserver-es/src/main/java/org/sonar/server/issue/index/IssueIndex.java @@ -99,7 +99,7 @@ import org.springframework.util.CollectionUtils; import static com.google.common.base.Preconditions.checkState; import static java.lang.String.format; import static java.util.Collections.singletonList; -import static java.util.stream.Collectors.toList; +import static java.util.stream.Collectors.toCollection; import static org.elasticsearch.index.query.QueryBuilders.boolQuery; import static org.elasticsearch.index.query.QueryBuilders.existsQuery; import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery; @@ -1245,7 +1245,8 @@ public class IssueIndex { List children = new ArrayList<>(); if (includeDistribution) { Stream stream = ((ParsedStringTerms) categoryBucket.getAggregations().get(AGG_DISTRIBUTION)).getBuckets().stream(); - children = stream.map(cweBucket -> processSecurityReportCategorySearchResults(cweBucket, cweBucket.getKeyAsString(), null, null)).collect(toList()); + children = stream.map(cweBucket -> processSecurityReportCategorySearchResults(cweBucket, cweBucket.getKeyAsString(), null, null)) + .collect(toCollection(ArrayList::new)); } return processSecurityReportCategorySearchResults(categoryBucket, categoryBucket.getName(), children, version); diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/Setting.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/Setting.java index a43fbf2c29a..6061483b15a 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/Setting.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/Setting.java @@ -20,11 +20,10 @@ package org.sonar.server.setting.ws; import com.google.common.base.Splitter; -import com.google.common.collect.ImmutableTable; import java.util.Collections; +import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.stream.Collectors; import javax.annotation.CheckForNull; import javax.annotation.Nullable; import org.sonar.api.config.PropertyDefinition; @@ -97,18 +96,17 @@ public class Setting { if (propertySets.isEmpty()) { return Collections.emptyList(); } - ImmutableTable.Builder tableBuilder = new ImmutableTable.Builder<>(); + Map> table = new HashMap<>(); propertySets.forEach(property -> { String keyWithoutSettingKey = property.getKey().replace(propertyKey + ".", ""); List setIdWithFieldKey = DOT_SPLITTER.splitToList(keyWithoutSettingKey); String setId = setIdWithFieldKey.get(0); String fieldKey = keyWithoutSettingKey.replaceFirst(setId + ".", ""); - tableBuilder.put(setId, fieldKey, property.getValue()); + table.computeIfAbsent(setId, k -> new HashMap<>()).put(fieldKey, property.getValue()); }); - ImmutableTable table = tableBuilder.build(); - return table.rowKeySet().stream() - .map(table::row) - .collect(Collectors.toList()); + return table.keySet().stream() + .map(table::get) + .toList(); } } -- 2.39.5