Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make static final Set constants immutable #13087

Merged
merged 6 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lucene/CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
---------------------

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -51,7 +52,8 @@ public enum Foldings {

private final Set<Foldings> foldings;

public static final Set<Foldings> ALL_FOLDINGS = EnumSet.allOf(Foldings.class);
public static final Set<Foldings> ALL_FOLDINGS =
Collections.unmodifiableSet(EnumSet.allOf(Foldings.class));

static final char AA = '\u00C5'; // Å
static final char aa = '\u00E5'; // å
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@
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;
Expand Down Expand Up @@ -55,10 +53,8 @@ public class TestFactories extends BaseTokenStreamTestCase {

/** Factories that are excluded from testing it with random data */
private static final Set<Class<? extends AbstractAnalysisFactory>> 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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@
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;
Expand Down Expand Up @@ -53,10 +51,8 @@ public class TestFactories extends BaseTokenStreamTestCase {

/** Factories that are excluded from testing it with random data */
private static final Set<Class<? extends AbstractAnalysisFactory>> 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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
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;
Expand Down Expand Up @@ -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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We changed that code recently, maybe check also the other Ancient indexes test.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TestAncientIndicesCompatibility.UNSUPPORTED_INDEXES is already immutable:

Or did you mean something else?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok all fine.

}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -25,7 +26,8 @@

public class TestFilterIterator extends LuceneTestCase {

private static final Set<String> set = new TreeSet<>(Arrays.asList("a", "b", "c"));
private static final Set<String> set =
Collections.unmodifiableSet(new TreeSet<>(Arrays.asList("a", "b", "c")));

private static void assertNoMore(Iterator<?> it) {
assertFalse(it.hasNext());
Expand Down