From 7570fc2e13637d741006836d149449f7b86c6f79 Mon Sep 17 00:00:00 2001 From: Rob Zienert Date: Fri, 20 Oct 2017 10:47:51 -0700 Subject: [PATCH] fix(cats): Remove unmodifiable collections from modifiable codepaths --- .../netflix/spinnaker/cats/agent/DefaultCacheResult.java | 4 ++-- .../spinnaker/cats/provider/DefaultProviderCache.java | 4 ++-- .../spinnaker/cats/dynomite/cache/DynomiteCache.java | 5 +---- .../spinnaker/cats/redis/cache/AbstractRedisCache.java | 7 +++---- 4 files changed, 8 insertions(+), 12 deletions(-) diff --git a/cats/cats-core/src/main/java/com/netflix/spinnaker/cats/agent/DefaultCacheResult.java b/cats/cats-core/src/main/java/com/netflix/spinnaker/cats/agent/DefaultCacheResult.java index 07be5f3de3f..ad8bd78a451 100644 --- a/cats/cats-core/src/main/java/com/netflix/spinnaker/cats/agent/DefaultCacheResult.java +++ b/cats/cats-core/src/main/java/com/netflix/spinnaker/cats/agent/DefaultCacheResult.java @@ -19,7 +19,7 @@ import com.netflix.spinnaker.cats.cache.CacheData; import java.util.Collection; -import java.util.Collections; +import java.util.HashMap; import java.util.Map; /** @@ -30,7 +30,7 @@ public class DefaultCacheResult implements CacheResult { private final Map> evictions; public DefaultCacheResult(Map> cacheResults) { - this(cacheResults, Collections.emptyMap()); + this(cacheResults, new HashMap<>()); } public DefaultCacheResult(Map> cacheResults, Map> evictions) { this.cacheResults = cacheResults; diff --git a/cats/cats-core/src/main/java/com/netflix/spinnaker/cats/provider/DefaultProviderCache.java b/cats/cats-core/src/main/java/com/netflix/spinnaker/cats/provider/DefaultProviderCache.java index 25f4f5bc801..6c4a2bf8f4c 100644 --- a/cats/cats-core/src/main/java/com/netflix/spinnaker/cats/provider/DefaultProviderCache.java +++ b/cats/cats-core/src/main/java/com/netflix/spinnaker/cats/provider/DefaultProviderCache.java @@ -189,11 +189,11 @@ private Collection buildResponse(Collection source) { private Collection getExistingSourceIdentifiers(String type, String sourceAgentType) { CacheData all = backingStore.get(type, ALL_ID); if (all == null) { - return Collections.emptySet(); + return new HashSet<>(); } Collection relationship = all.getRelationships().get(sourceAgentType); if (relationship == null) { - return Collections.emptySet(); + return new HashSet<>(); } return relationship; } diff --git a/cats/cats-dynomite/src/main/java/com/netflix/spinnaker/cats/dynomite/cache/DynomiteCache.java b/cats/cats-dynomite/src/main/java/com/netflix/spinnaker/cats/dynomite/cache/DynomiteCache.java index 7d162b9f087..ec0e1b5ebea 100644 --- a/cats/cats-dynomite/src/main/java/com/netflix/spinnaker/cats/dynomite/cache/DynomiteCache.java +++ b/cats/cats-dynomite/src/main/java/com/netflix/spinnaker/cats/dynomite/cache/DynomiteCache.java @@ -217,9 +217,7 @@ protected void evictItems(String type, List identifiers, Collection redisClientDelegate.withPipeline(pipeline -> { DynoJedisPipeline p = (DynoJedisPipeline) pipeline; - boolean pipelineHasOps = false; for (List idPartition : Lists.partition(identifiers, options.getMaxDelSize())) { - pipelineHasOps = true; String[] ids = idPartition.toArray(new String[idPartition.size()]); pipeline.srem(allOfTypeId(type), ids); sremOperations.incrementAndGet(); @@ -228,14 +226,13 @@ protected void evictItems(String type, List identifiers, Collection items) { @Override public void evict(String type, String id) { - evictAll(type, Collections.singletonList(id)); + evictAll(type, Arrays.asList(id)); } @Override @@ -97,7 +96,7 @@ public CacheData get(String type, String id) { @Override public CacheData get(String type, String id, CacheFilter cacheFilter) { - Collection result = getAll(type, Collections.singletonList(id), cacheFilter); + Collection result = getAll(type, Arrays.asList(id), cacheFilter); if (result.isEmpty()) { return null; }