diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt index d4aa36a7881..af02dcbf246 100644 --- a/lucene/CHANGES.txt +++ b/lucene/CHANGES.txt @@ -195,6 +195,9 @@ Improvements * GITHUB#13041: TokenizedPhraseQueryNode code cleanup (Dmitry Cherniachenko) +* GITHUB#13087: Changed `static final Set` constants to be immutable. Among others it affected + ScandinavianNormalizer.ALL_FOLDINGS set with public access. (Dmitry Cherniachenko) + Optimizations --------------------- diff --git a/lucene/analysis/common/src/java/org/apache/lucene/analysis/miscellaneous/ScandinavianNormalizer.java b/lucene/analysis/common/src/java/org/apache/lucene/analysis/miscellaneous/ScandinavianNormalizer.java index 50187264a78..6654929d559 100644 --- a/lucene/analysis/common/src/java/org/apache/lucene/analysis/miscellaneous/ScandinavianNormalizer.java +++ b/lucene/analysis/common/src/java/org/apache/lucene/analysis/miscellaneous/ScandinavianNormalizer.java @@ -16,6 +16,7 @@ */ package org.apache.lucene.analysis.miscellaneous; +import java.util.Collections; import java.util.EnumSet; import java.util.Set; import org.apache.lucene.analysis.util.StemmerUtil; @@ -51,7 +52,8 @@ public final class ScandinavianNormalizer { private final Set foldings; - public static final Set ALL_FOLDINGS = EnumSet.allOf(Foldings.class); + public static final Set ALL_FOLDINGS = + Collections.unmodifiableSet(EnumSet.allOf(Foldings.class)); static final char AA = '\u00C5'; // Å static final char aa = '\u00E5'; // å diff --git a/lucene/analysis/common/src/test/org/apache/lucene/analysis/core/TestFactories.java b/lucene/analysis/common/src/test/org/apache/lucene/analysis/core/TestFactories.java index 5ae7b111024..11c7cacef30 100644 --- a/lucene/analysis/common/src/test/org/apache/lucene/analysis/core/TestFactories.java +++ b/lucene/analysis/common/src/test/org/apache/lucene/analysis/core/TestFactories.java @@ -20,9 +20,7 @@ import java.io.IOException; import java.io.Reader; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; -import java.util.Arrays; import java.util.HashMap; -import java.util.HashSet; import java.util.Map; import java.util.Set; import org.apache.lucene.analysis.AbstractAnalysisFactory; @@ -55,10 +53,8 @@ public class TestFactories extends BaseTokenStreamTestCase { /** Factories that are excluded from testing it with random data */ private static final Set> EXCLUDE_FACTORIES_RANDOM_DATA = - new HashSet<>( - Arrays.asList( - DelimitedTermFrequencyTokenFilterFactory.class, - DelimitedBoostTokenFilterFactory.class)); + Set.of( + DelimitedTermFrequencyTokenFilterFactory.class, DelimitedBoostTokenFilterFactory.class); public void test() throws IOException { for (String tokenizer : TokenizerFactory.availableTokenizers()) { diff --git a/lucene/analysis/kuromoji/src/test/org/apache/lucene/analysis/ja/TestFactories.java b/lucene/analysis/kuromoji/src/test/org/apache/lucene/analysis/ja/TestFactories.java index b05d5edadc3..2fdbfc395d3 100644 --- a/lucene/analysis/kuromoji/src/test/org/apache/lucene/analysis/ja/TestFactories.java +++ b/lucene/analysis/kuromoji/src/test/org/apache/lucene/analysis/ja/TestFactories.java @@ -20,9 +20,7 @@ import java.io.IOException; import java.io.Reader; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; -import java.util.Arrays; import java.util.HashMap; -import java.util.HashSet; import java.util.Map; import java.util.Set; import org.apache.lucene.analysis.AbstractAnalysisFactory; @@ -53,10 +51,8 @@ public class TestFactories extends BaseTokenStreamTestCase { /** Factories that are excluded from testing it with random data */ private static final Set> EXCLUDE_FACTORIES_RANDOM_DATA = - new HashSet<>( - Arrays.asList( - DelimitedTermFrequencyTokenFilterFactory.class, - DelimitedBoostTokenFilterFactory.class)); + Set.of( + DelimitedTermFrequencyTokenFilterFactory.class, DelimitedBoostTokenFilterFactory.class); public void test() throws IOException { for (String tokenizer : TokenizerFactory.availableTokenizers()) { diff --git a/lucene/backward-codecs/src/test/org/apache/lucene/backward_index/BackwardsCompatibilityTestBase.java b/lucene/backward-codecs/src/test/org/apache/lucene/backward_index/BackwardsCompatibilityTestBase.java index 04baa47425e..ae5920de368 100644 --- a/lucene/backward-codecs/src/test/org/apache/lucene/backward_index/BackwardsCompatibilityTestBase.java +++ b/lucene/backward-codecs/src/test/org/apache/lucene/backward_index/BackwardsCompatibilityTestBase.java @@ -29,6 +29,7 @@ import java.nio.file.Paths; import java.nio.file.StandardOpenOption; import java.text.ParseException; import java.util.ArrayList; +import java.util.Collections; import java.util.HashSet; import java.util.Iterator; import java.util.LinkedHashSet; @@ -98,7 +99,7 @@ public abstract class BackwardsCompatibilityTestBase extends LuceneTestCase { // make sure we never miss a version. assertTrue("Version: " + version + " missing", binaryVersions.remove(version)); } - BINARY_SUPPORTED_VERSIONS = binaryVersions; + BINARY_SUPPORTED_VERSIONS = Collections.unmodifiableSet(binaryVersions); } /** diff --git a/lucene/core/src/test/org/apache/lucene/util/TestFilterIterator.java b/lucene/core/src/test/org/apache/lucene/util/TestFilterIterator.java index a96cf4d40de..275d8e2e9a6 100644 --- a/lucene/core/src/test/org/apache/lucene/util/TestFilterIterator.java +++ b/lucene/core/src/test/org/apache/lucene/util/TestFilterIterator.java @@ -17,6 +17,7 @@ package org.apache.lucene.util; import java.util.Arrays; +import java.util.Collections; import java.util.Iterator; import java.util.NoSuchElementException; import java.util.Set; @@ -25,7 +26,8 @@ import org.apache.lucene.tests.util.LuceneTestCase; public class TestFilterIterator extends LuceneTestCase { - private static final Set set = new TreeSet<>(Arrays.asList("a", "b", "c")); + private static final Set set = + Collections.unmodifiableSet(new TreeSet<>(Arrays.asList("a", "b", "c"))); private static void assertNoMore(Iterator it) { assertFalse(it.hasNext());