diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index 31c0616381a..ffaf08bec84 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -239,6 +239,9 @@ Other Changes * SOLR-14731: Rename @SolrSingleThreaded to @SolrThreadUnsafe, mark DistribPackageStore with the annotation (marcussorealheis) +* SOLR-14579: Comment SolrJ 'Utils' generic map functions + (Megan Carey and a lot of education from Uwe Schindler via Erick Erickson) + ================== 8.6.2 ================== Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release. diff --git a/solr/core/src/java/org/apache/solr/handler/admin/ContainerPluginsApi.java b/solr/core/src/java/org/apache/solr/handler/admin/ContainerPluginsApi.java index 21c16e344d2..0c7a48726cd 100644 --- a/solr/core/src/java/org/apache/solr/handler/admin/ContainerPluginsApi.java +++ b/solr/core/src/java/org/apache/solr/handler/admin/ContainerPluginsApi.java @@ -151,7 +151,7 @@ public class ContainerPluginsApi { SolrZkClient zkClient = zkClientSupplier.get(); try { Map clusterPropsJson = (Map) Utils.fromJSON(zkClient.getData(ZkStateReader.CLUSTER_PROPS, null, new Stat(), true)); - return (Map) clusterPropsJson.computeIfAbsent(PLUGIN, Utils.NEW_LINKED_HASHMAP_FUN); + return (Map) clusterPropsJson.computeIfAbsent(PLUGIN, o -> new LinkedHashMap<>()); } catch (KeeperException.NoNodeException e) { return new LinkedHashMap<>(); } catch (KeeperException | InterruptedException e) { @@ -165,7 +165,7 @@ public class ContainerPluginsApi { zkClientSupplier.get().atomicUpdate(ZkStateReader.CLUSTER_PROPS, bytes -> { Map rawJson = bytes == null ? new LinkedHashMap() : (Map) Utils.fromJSON(bytes); - Map pluginsModified = modifier.apply((Map) rawJson.computeIfAbsent(PLUGIN, Utils.NEW_LINKED_HASHMAP_FUN)); + Map pluginsModified = modifier.apply((Map) rawJson.computeIfAbsent(PLUGIN, o -> new LinkedHashMap<>())); if (pluginsModified == null) return null; rawJson.put(PLUGIN, pluginsModified); return Utils.toJSON(rawJson); diff --git a/solr/core/src/java/org/apache/solr/pkg/PackageAPI.java b/solr/core/src/java/org/apache/solr/pkg/PackageAPI.java index 5a354ab1b85..5fe3aaa3043 100644 --- a/solr/core/src/java/org/apache/solr/pkg/PackageAPI.java +++ b/solr/core/src/java/org/apache/solr/pkg/PackageAPI.java @@ -282,15 +282,11 @@ public class PackageAPI { log.error("Error deserializing packages.json", e); packages = new Packages(); } - @SuppressWarnings({"rawtypes"}) - List list = packages.packages.computeIfAbsent(add.pkg, Utils.NEW_ARRAYLIST_FUN); - for (Object o : list) { - if (o instanceof PkgVersion) { - PkgVersion version = (PkgVersion) o; - if (Objects.equals(version.version, add.version)) { - payload.addError("Version '" + add.version + "' exists already"); - return null; - } + List list = packages.packages.computeIfAbsent(add.pkg, o -> new ArrayList<>()); + for (PkgVersion version : list) { + if (Objects.equals(version.version, add.version)) { + payload.addError("Version '" + add.version + "' exists already"); + return null; } } list.add(new PkgVersion(add)); diff --git a/solr/core/src/java/org/apache/solr/search/stats/ExactStatsCache.java b/solr/core/src/java/org/apache/solr/search/stats/ExactStatsCache.java index e0ffee224c2..a503f054bc2 100644 --- a/solr/core/src/java/org/apache/solr/search/stats/ExactStatsCache.java +++ b/solr/core/src/java/org/apache/solr/search/stats/ExactStatsCache.java @@ -42,7 +42,6 @@ import org.apache.solr.common.SolrException.ErrorCode; import org.apache.solr.common.params.ModifiableSolrParams; import org.apache.solr.common.params.ShardParams; import org.apache.solr.common.util.NamedList; -import org.apache.solr.common.util.Utils; import org.apache.solr.handler.component.ResponseBuilder; import org.apache.solr.handler.component.ShardRequest; import org.apache.solr.handler.component.ShardResponse; @@ -130,7 +129,7 @@ public class ExactStatsCache extends StatsCache { protected void addToPerShardColStats(SolrQueryRequest req, String shard, Map colStats) { @SuppressWarnings({"unchecked"}) - Map> perShardColStats = (Map>) req.getContext().computeIfAbsent(PER_SHARD_COL_STATS, Utils.NEW_HASHMAP_FUN); + Map> perShardColStats = (Map>) req.getContext().computeIfAbsent(PER_SHARD_COL_STATS, o -> new HashMap<>()); perShardColStats.put(shard, colStats); } @@ -146,7 +145,7 @@ public class ExactStatsCache extends StatsCache { Map termStats = StatsUtil.termStatsMapFromString(termStatsString); if (termStats != null) { @SuppressWarnings({"unchecked"}) - Map> perShardTermStats = (Map>) req.getContext().computeIfAbsent(PER_SHARD_TERM_STATS, Utils.NEW_HASHMAP_FUN); + Map> perShardTermStats = (Map>) req.getContext().computeIfAbsent(PER_SHARD_TERM_STATS, o -> new HashMap<>()); perShardTermStats.put(shard, termStats); } } @@ -318,13 +317,13 @@ public class ExactStatsCache extends StatsCache { protected void addToGlobalColStats(SolrQueryRequest req, Entry e) { @SuppressWarnings({"unchecked"}) - Map currentGlobalColStats = (Map) req.getContext().computeIfAbsent(CURRENT_GLOBAL_COL_STATS, Utils.NEW_HASHMAP_FUN); + Map currentGlobalColStats = (Map) req.getContext().computeIfAbsent(CURRENT_GLOBAL_COL_STATS, o -> new HashMap<>()); currentGlobalColStats.put(e.getKey(), e.getValue()); } protected void addToGlobalTermStats(SolrQueryRequest req, Entry e) { @SuppressWarnings({"unchecked"}) - Map currentGlobalTermStats = (Map) req.getContext().computeIfAbsent(CURRENT_GLOBAL_TERM_STATS, Utils.NEW_HASHMAP_FUN); + Map currentGlobalTermStats = (Map) req.getContext().computeIfAbsent(CURRENT_GLOBAL_TERM_STATS, o -> new HashMap<>()); currentGlobalTermStats.put(e.getKey(), e.getValue()); } diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/SolrClientNodeStateProvider.java b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/SolrClientNodeStateProvider.java index 1c0c225de6a..2620dc4abcb 100644 --- a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/SolrClientNodeStateProvider.java +++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/SolrClientNodeStateProvider.java @@ -147,9 +147,7 @@ public class SolrClientNodeStateProvider implements NodeStateProvider, MapWriter } @Override public Map>> getReplicaInfo(String node, Collection keys) { - @SuppressWarnings({"unchecked"}) - Map>> result = nodeVsCollectionVsShardVsReplicaInfo.computeIfAbsent(node, Utils.NEW_HASHMAP_FUN); - if (!keys.isEmpty()) { + Map>> result = nodeVsCollectionVsShardVsReplicaInfo.computeIfAbsent(node, o -> new HashMap<>()); if (!keys.isEmpty()) { Map> metricsKeyVsTagReplica = new HashMap<>(); forEachReplica(result, r -> { for (String key : keys) { diff --git a/solr/solrj/src/java/org/apache/solr/common/util/Utils.java b/solr/solrj/src/java/org/apache/solr/common/util/Utils.java index 0a4485b975f..669df38f3fb 100644 --- a/solr/solrj/src/java/org/apache/solr/common/util/Utils.java +++ b/solr/solrj/src/java/org/apache/solr/common/util/Utils.java @@ -52,7 +52,6 @@ import java.util.TreeSet; import java.util.concurrent.Callable; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicLong; import java.util.function.BiConsumer; import java.util.function.Function; import java.util.regex.Matcher; @@ -97,18 +96,6 @@ import static java.util.concurrent.TimeUnit.NANOSECONDS; public class Utils { - @SuppressWarnings({"rawtypes"}) - public static final Function NEW_HASHMAP_FUN = o -> new HashMap<>(); - @SuppressWarnings({"rawtypes"}) - public static final Function NEW_LINKED_HASHMAP_FUN = o -> new LinkedHashMap<>(); - @SuppressWarnings({"rawtypes"}) - public static final Function NEW_ATOMICLONG_FUN = o -> new AtomicLong(); - @SuppressWarnings({"rawtypes"}) - public static final Function NEW_ARRAYLIST_FUN = o -> new ArrayList<>(); - @SuppressWarnings({"rawtypes"}) - public static final Function NEW_SYNCHRONIZED_ARRAYLIST_FUN = o -> Collections.synchronizedList(new ArrayList<>()); - @SuppressWarnings({"rawtypes"}) - public static final Function NEW_HASHSET_FUN = o -> new HashSet<>(); private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); @SuppressWarnings({"rawtypes"}) diff --git a/solr/solrj/src/test/org/apache/solr/common/util/TestFastJavabinDecoder.java b/solr/solrj/src/test/org/apache/solr/common/util/TestFastJavabinDecoder.java index 5e7d774174a..47fef9a1783 100644 --- a/solr/solrj/src/test/org/apache/solr/common/util/TestFastJavabinDecoder.java +++ b/solr/solrj/src/test/org/apache/solr/common/util/TestFastJavabinDecoder.java @@ -35,9 +35,6 @@ import org.apache.solr.common.SolrDocument; import org.apache.solr.common.SolrDocumentList; import org.apache.solr.common.util.FastJavaBinDecoder.Tag; -import static org.apache.solr.common.util.Utils.NEW_ARRAYLIST_FUN; -import static org.apache.solr.common.util.Utils.NEW_LINKED_HASHMAP_FUN; - public class TestFastJavabinDecoder extends SolrTestCaseJ4 { public void testTagRead() throws Exception { @@ -96,20 +93,18 @@ public class TestFastJavabinDecoder extends SolrTestCaseJ4 { assertEquals(Utils.writeJson(m2, new StringWriter(), true).toString(), Utils.writeJson(fastMap, new StringWriter(), true).toString()); - @SuppressWarnings({"unchecked"}) + @SuppressWarnings({"unchecked", "rawtypes"}) Object newMap = new FastJavaBinDecoder() .withInputStream(new FastInputStream(null, baos.getbuf(), 0, baos.size())) .decode(e -> { e.listenContainer(new LinkedHashMap<>(), e_ -> { - @SuppressWarnings({"rawtypes"}) Map rootMap = (Map) e_.ctx(); if (e_.type() == DataEntry.Type.ENTRY_ITER) { - e_.listenContainer(rootMap.computeIfAbsent(e_.name(), NEW_ARRAYLIST_FUN), + e_.listenContainer(rootMap.computeIfAbsent(e_.name(), o -> new ArrayList<>()), FastJavaBinDecoder.getEntryListener()); } else if (e_.type() == DataEntry.Type.KEYVAL_ITER) { - e_.listenContainer(rootMap.computeIfAbsent(e_.name(), NEW_LINKED_HASHMAP_FUN), e1 -> { - @SuppressWarnings({"rawtypes"}) - Map m1 = (Map) e1.ctx(); + e_.listenContainer(rootMap.computeIfAbsent(e_.name(), o -> new LinkedHashMap<>()), e1 -> { + Map m1 = (Map) e1.ctx(); if ("k1".equals(e1.name())) { m1.put(e1.name(), e1.val().toString()); }