Apache Solr open-source search software
LUCENE-8927: Set.copyOf and Set.of instead of Collections.unmodifiabl… (#796)
Atri Sharma3e2ca05b8eac
diff --git a/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/feeds/DemoHTMLParser.java b/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/feeds/DemoHTMLParser.javaindex a1e6a3c013f..79eafbc5415 100644--- a/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/feeds/DemoHTMLParser.java+++ b/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/feeds/DemoHTMLParser.java@@ -145,21 +145,17 @@ public class DemoHTMLParser implements HTMLParser {// assign body textthis.body = body.toString();}-- private static final Set<String> createElementNameSet(String... names) {- return Collections.unmodifiableSet(new HashSet<>(Arrays.asList(names)));- }-+/** HTML elements that cause a line break (they are block-elements) */- static final Set<String> ENDLINE_ELEMENTS = createElementNameSet(- "p", "h1", "h2", "h3", "h4", "h5", "h6", "div", "ul", "ol", "dl",- "pre", "hr", "blockquote", "address", "fieldset", "table", "form",- "noscript", "li", "dt", "dd", "noframes", "br", "tr", "select", "option"+ static final Set<String> ENDLINE_ELEMENTS = Set.of(+ "p", "h1", "h2", "h3", "h4", "h5", "h6", "div", "ul", "ol", "dl",+ "pre", "hr", "blockquote", "address", "fieldset", "table", "form",+ "noscript", "li", "dt", "dd", "noframes", "br", "tr", "select", "option");/** HTML elements with contents that are ignored */- static final Set<String> SUPPRESS_ELEMENTS = createElementNameSet(- "style", "script"+ static final Set<String> SUPPRESS_ELEMENTS = Set.of(+ "style", "script");}diff --git a/lucene/core/src/java/org/apache/lucene/index/FieldInfos.java b/lucene/core/src/java/org/apache/lucene/index/FieldInfos.javaindex d9076d767d0..979a248f705 100644--- a/lucene/core/src/java/org/apache/lucene/index/FieldInfos.java+++ b/lucene/core/src/java/org/apache/lucene/index/FieldInfos.java@@ -421,7 +421,7 @@ public class FieldInfos implements Iterable<FieldInfo> {return dvType == docValuesType.get(fieldName);}}-+synchronized void clear() {numberToName.clear();nameToNumber.clear();diff --git a/lucene/core/src/java/org/apache/lucene/store/FSDirectory.java b/lucene/core/src/java/org/apache/lucene/store/FSDirectory.javaindex cbaafb2f86d..d20df51d3ee 100644--- a/lucene/core/src/java/org/apache/lucene/store/FSDirectory.java+++ b/lucene/core/src/java/org/apache/lucene/store/FSDirectory.java@@ -428,7 +428,7 @@ public abstract class FSDirectory extends BaseDirectory {if (pendingDeletes.isEmpty()) {return Collections.emptySet();} else {- return Collections.unmodifiableSet(new HashSet<>(pendingDeletes));+ return Set.copyOf(pendingDeletes);}}}diff --git a/lucene/replicator/src/java/org/apache/lucene/replicator/nrt/PrimaryNode.java b/lucene/replicator/src/java/org/apache/lucene/replicator/nrt/PrimaryNode.javaindex 6b90c7843e5..f96f6d23395 100644--- a/lucene/replicator/src/java/org/apache/lucene/replicator/nrt/PrimaryNode.java+++ b/lucene/replicator/src/java/org/apache/lucene/replicator/nrt/PrimaryNode.java@@ -136,7 +136,7 @@ public abstract class PrimaryNode extends Node {message("top: now flushAndRefresh");Set<String> completedMergeFiles;synchronized(finishedMergedFiles) {- completedMergeFiles = Collections.unmodifiableSet(new HashSet<>(finishedMergedFiles));+ completedMergeFiles = Set.copyOf(finishedMergedFiles);}mgr.maybeRefreshBlocking();boolean result = setCurrentInfos(completedMergeFiles);diff --git a/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java b/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.javaindex d6a875fcd9c..c0083b9167a 100644--- a/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java+++ b/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java@@ -593,14 +593,13 @@ public abstract class LuceneTestCase extends Assert {private final static long STATIC_LEAK_THRESHOLD = 10 * 1024 * 1024;/** By-name list of ignored types like loggers etc. */- private final static Set<String> STATIC_LEAK_IGNORED_TYPES = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(+ private final static Set<String> STATIC_LEAK_IGNORED_TYPES = Set.of("org.slf4j.Logger","org.apache.solr.SolrLogFormatter",- "java.io.File", // Solr sometimes refers to this in a static way, but it has a "java.nio.fs.Path" inside+ "java.io.File", // Solr sometimes refers to this in a static way, but it has a "java.nio.fs.Path" insidePath.class.getName(), // causes problems because interface is implemented by hidden classesClass.class.getName(),- EnumSet.class.getName()- )));+ EnumSet.class.getName());/*** This controls how suite-level rules are nested. It is important that _all_ rules declared