From 16588ffe1e54e23d4475fe5a871000e8266d54a9 Mon Sep 17 00:00:00 2001 From: Jeremy Kong Date: Tue, 14 Dec 2021 21:22:57 +0000 Subject: [PATCH] [Exclusion Hunter] Part 21: ModifyCollectionInEnhancedForLoop (#5795) * shady-removal * fix Co-authored-by: Glenn Sheasby --- .../atlasdb/keyvalue/cassandra/Blacklist.java | 11 ++++++++--- build.gradle | 1 - 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/atlasdb-cassandra/src/main/java/com/palantir/atlasdb/keyvalue/cassandra/Blacklist.java b/atlasdb-cassandra/src/main/java/com/palantir/atlasdb/keyvalue/cassandra/Blacklist.java index 0f61be3cfc7..5e2474cbe62 100644 --- a/atlasdb-cassandra/src/main/java/com/palantir/atlasdb/keyvalue/cassandra/Blacklist.java +++ b/atlasdb-cassandra/src/main/java/com/palantir/atlasdb/keyvalue/cassandra/Blacklist.java @@ -26,8 +26,10 @@ import java.net.InetSocketAddress; import java.time.Clock; import java.util.Collection; +import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.Map.Entry; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.TimeUnit; @@ -54,17 +56,20 @@ public Blacklist(CassandraKeyValueServiceConfig config) { void checkAndUpdate(Map pools) { // Check blacklist and re-integrate or continue to wait as necessary - for (Map.Entry blacklistedEntry : blacklist.entrySet()) { + Iterator> blacklistIterator = + blacklist.entrySet().iterator(); + while (blacklistIterator.hasNext()) { + Map.Entry blacklistedEntry = blacklistIterator.next(); if (coolOffPeriodExpired(blacklistedEntry)) { InetSocketAddress host = blacklistedEntry.getKey(); if (!pools.containsKey(host)) { // Probably the pool changed underneath us - blacklist.remove(host); + blacklistIterator.remove(); log.info( "Removing host {} from the blacklist as it wasn't found in the pool.", SafeArg.of("host", CassandraLogHelper.host(host))); } else if (isHostHealthy(pools.get(host))) { - blacklist.remove(host); + blacklistIterator.remove(); log.info( "Added host {} back into the pool after a waiting period and successful health check.", SafeArg.of("host", CassandraLogHelper.host(host))); diff --git a/build.gradle b/build.gradle index a3c894e470f..a21db633f3d 100644 --- a/build.gradle +++ b/build.gradle @@ -102,7 +102,6 @@ allprojects { 'FutureReturnValueIgnored', 'InlineFormatString', 'MixedMutabilityReturnType', - 'ModifyCollectionInEnhancedForLoop', 'NarrowingCompoundAssignment', 'PreconditionsConstantMessage', 'PreconditionsInvalidPlaceholder',