From 1274db1ae6f9744b9ba78e87e79be6812240e659 Mon Sep 17 00:00:00 2001 From: ChrisHegarty Date: Fri, 3 Nov 2023 14:48:30 +0000 Subject: [PATCH 01/23] initial commit for java 21 --- build.gradle | 8 +++++++- buildSrc/scriptDepVersions.gradle | 2 +- .../lucene/analysis/br/BrazilianStemmer.java | 2 +- .../lucene/analysis/de/GermanStemmer.java | 2 +- .../lucene/analysis/th/ThaiTokenizer.java | 2 +- .../collation/TestCollationKeyAnalyzer.java | 2 +- .../standard/GenerateJflexTLDMacros.java | 3 ++- .../icu/TestICUCollationKeyAnalyzer.java | 2 +- .../analysis/icu/GenerateUTR30DataFiles.java | 17 +++++++++-------- .../lucene/benchmark/byTask/PerfRunData.java | 9 ++++++++- .../benchmark/byTask/tasks/NewLocaleTask.java | 4 ++-- .../benchmark/byTask/TestPerfTasksLogic.java | 16 ++++++++-------- .../benchmark/byTask/feeds/TestHtmlParser.java | 2 +- .../apache/lucene/util/TestWeakIdentityMap.java | 10 ++++++++-- .../search/QueryParserPaneProvider.java | 2 +- .../lucene/luke/app/desktop/util/URLLabel.java | 3 ++- .../queryparser/flexible/messages/TestNLS.java | 2 +- 17 files changed, 55 insertions(+), 33 deletions(-) diff --git a/build.gradle b/build.gradle index f396a7724b9..9c64ab1c3ab 100644 --- a/build.gradle +++ b/build.gradle @@ -73,7 +73,7 @@ ext { } // Minimum Java version required to compile and run Lucene. - minJavaVersion = JavaVersion.VERSION_17 + minJavaVersion = JavaVersion.VERSION_21 // snapshot build marker used in scripts. snapshotBuild = version.contains("SNAPSHOT") @@ -101,6 +101,12 @@ dependencies { groovy "org.codehaus.groovy:groovy-all:3.0.12" } +repositories { + maven { + url "https://repo.eclipse.org/content/repositories/eclipse-snapshots/" + } +} + apply from: file('buildSrc/scriptDepVersions.gradle') // Include smaller chunks configuring dedicated build areas. diff --git a/buildSrc/scriptDepVersions.gradle b/buildSrc/scriptDepVersions.gradle index 991ff18dcff..795ce08366c 100644 --- a/buildSrc/scriptDepVersions.gradle +++ b/buildSrc/scriptDepVersions.gradle @@ -24,7 +24,7 @@ ext { "apache-rat": "0.14", "asm": "9.6", "commons-codec": "1.13", - "ecj": "3.30.0", + "ecj": "3.36.0-SNAPSHOT", "flexmark": "0.61.24", "javacc": "7.0.12", "jflex": "1.8.2", diff --git a/lucene/analysis/common/src/java/org/apache/lucene/analysis/br/BrazilianStemmer.java b/lucene/analysis/common/src/java/org/apache/lucene/analysis/br/BrazilianStemmer.java index f5647fceeff..c4106edefd1 100644 --- a/lucene/analysis/common/src/java/org/apache/lucene/analysis/br/BrazilianStemmer.java +++ b/lucene/analysis/common/src/java/org/apache/lucene/analysis/br/BrazilianStemmer.java @@ -20,7 +20,7 @@ import java.util.Locale; /** A stemmer for Brazilian Portuguese words. */ class BrazilianStemmer { - private static final Locale locale = new Locale("pt", "BR"); + private static final Locale locale = Locale.of("pt", "BR"); /** Changed term */ private String TERM; diff --git a/lucene/analysis/common/src/java/org/apache/lucene/analysis/de/GermanStemmer.java b/lucene/analysis/common/src/java/org/apache/lucene/analysis/de/GermanStemmer.java index ba668b238ef..3d4b1908db8 100644 --- a/lucene/analysis/common/src/java/org/apache/lucene/analysis/de/GermanStemmer.java +++ b/lucene/analysis/common/src/java/org/apache/lucene/analysis/de/GermanStemmer.java @@ -33,7 +33,7 @@ class GermanStemmer { /** Amount of characters that are removed with substitute() while stemming. */ private int substCount = 0; - private static final Locale locale = new Locale("de", "DE"); + private static final Locale locale = Locale.of("de", "DE"); /** * Stemms the given term to an unique discriminator. diff --git a/lucene/analysis/common/src/java/org/apache/lucene/analysis/th/ThaiTokenizer.java b/lucene/analysis/common/src/java/org/apache/lucene/analysis/th/ThaiTokenizer.java index d098d753fb0..e6e933a1fba 100644 --- a/lucene/analysis/common/src/java/org/apache/lucene/analysis/th/ThaiTokenizer.java +++ b/lucene/analysis/common/src/java/org/apache/lucene/analysis/th/ThaiTokenizer.java @@ -38,7 +38,7 @@ public class ThaiTokenizer extends SegmentingTokenizerBase { */ public static final boolean DBBI_AVAILABLE; - private static final BreakIterator proto = BreakIterator.getWordInstance(new Locale("th")); + private static final BreakIterator proto = BreakIterator.getWordInstance(Locale.of("th")); static { // check that we have a working dictionary-based break iterator for thai diff --git a/lucene/analysis/common/src/test/org/apache/lucene/collation/TestCollationKeyAnalyzer.java b/lucene/analysis/common/src/test/org/apache/lucene/collation/TestCollationKeyAnalyzer.java index 7ecfb7b58b3..f74e2a7bdd8 100644 --- a/lucene/analysis/common/src/test/org/apache/lucene/collation/TestCollationKeyAnalyzer.java +++ b/lucene/analysis/common/src/test/org/apache/lucene/collation/TestCollationKeyAnalyzer.java @@ -26,7 +26,7 @@ public class TestCollationKeyAnalyzer extends CollationTestBase { // Neither Java 1.4.2 nor 1.5.0 has Farsi Locale collation available in // RuleBasedCollator. However, the Arabic Locale seems to order the Farsi // characters properly. - private Collator collator = Collator.getInstance(new Locale("ar")); + private Collator collator = Collator.getInstance(Locale.of("ar")); private Analyzer analyzer; @Override diff --git a/lucene/analysis/common/src/tools/java/org/apache/lucene/analysis/standard/GenerateJflexTLDMacros.java b/lucene/analysis/common/src/tools/java/org/apache/lucene/analysis/standard/GenerateJflexTLDMacros.java index 24646e31a41..c205a9eea3f 100644 --- a/lucene/analysis/common/src/tools/java/org/apache/lucene/analysis/standard/GenerateJflexTLDMacros.java +++ b/lucene/analysis/common/src/tools/java/org/apache/lucene/analysis/standard/GenerateJflexTLDMacros.java @@ -21,6 +21,7 @@ import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.Writer; +import java.net.URI; import java.net.URL; import java.net.URLConnection; import java.nio.charset.StandardCharsets; @@ -111,7 +112,7 @@ public class GenerateJflexTLDMacros { public GenerateJflexTLDMacros(String tldFileURL, String jflexFile, String tldListFile) throws Exception { - this.tldFileURL = new URL(tldFileURL); + this.tldFileURL = URI.create(tldFileURL).toURL(); this.jflexMacroFile = Paths.get(jflexFile); this.tldListFile = Paths.get(tldListFile); } diff --git a/lucene/analysis/icu/src/test/org/apache/lucene/analysis/icu/TestICUCollationKeyAnalyzer.java b/lucene/analysis/icu/src/test/org/apache/lucene/analysis/icu/TestICUCollationKeyAnalyzer.java index e9141c242b8..0b49005176e 100644 --- a/lucene/analysis/icu/src/test/org/apache/lucene/analysis/icu/TestICUCollationKeyAnalyzer.java +++ b/lucene/analysis/icu/src/test/org/apache/lucene/analysis/icu/TestICUCollationKeyAnalyzer.java @@ -24,7 +24,7 @@ import org.apache.lucene.util.BytesRef; public class TestICUCollationKeyAnalyzer extends CollationTestBase { - private Collator collator = Collator.getInstance(new Locale("fa")); + private Collator collator = Collator.getInstance(Locale.of("fa")); private Analyzer analyzer; @Override diff --git a/lucene/analysis/icu/src/tools/java/org/apache/lucene/analysis/icu/GenerateUTR30DataFiles.java b/lucene/analysis/icu/src/tools/java/org/apache/lucene/analysis/icu/GenerateUTR30DataFiles.java index c48ed42d5a7..1735643bf54 100644 --- a/lucene/analysis/icu/src/tools/java/org/apache/lucene/analysis/icu/GenerateUTR30DataFiles.java +++ b/lucene/analysis/icu/src/tools/java/org/apache/lucene/analysis/icu/GenerateUTR30DataFiles.java @@ -27,6 +27,7 @@ import java.io.InputStreamReader; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.Writer; +import java.net.URI; import java.net.URL; import java.net.URLConnection; import java.nio.charset.StandardCharsets; @@ -155,19 +156,19 @@ public class GenerateUTR30DataFiles { } private static void getNFKCDataFilesFromIcuProject(String releaseTag) throws IOException { - URL icuTagsURL = new URL(ICU_GIT_TAG_URL + "/"); - URL icuReleaseTagURL = new URL(icuTagsURL, releaseTag + "/"); - URL norm2url = new URL(icuReleaseTagURL, ICU_DATA_NORM2_PATH + "/"); + URI icuTagsURL = URI.create(ICU_GIT_TAG_URL + "/"); + URI icuReleaseTagURL = icuTagsURL.resolve(releaseTag + "/"); + URI norm2url = icuReleaseTagURL.resolve(ICU_DATA_NORM2_PATH + "/"); System.err.print("Downloading " + NFKC_TXT + " ... "); - download(new URL(norm2url, NFKC_TXT), NFKC_TXT); + download(norm2url.resolve(NFKC_TXT), NFKC_TXT); System.err.println("done."); System.err.print("Downloading " + NFKC_CF_TXT + " ... "); - download(new URL(norm2url, NFKC_CF_TXT), NFKC_CF_TXT); + download(norm2url.resolve(NFKC_CF_TXT), NFKC_CF_TXT); System.err.println("done."); System.err.print("Downloading " + NFKC_CF_TXT + " and making diacritic rules one-way ... "); - URLConnection connection = openConnection(new URL(norm2url, NFC_TXT)); + URLConnection connection = openConnection(norm2url.resolve(NFC_TXT).toURL()); try (BufferedReader reader = new BufferedReader( new InputStreamReader(connection.getInputStream(), StandardCharsets.UTF_8)); @@ -210,8 +211,8 @@ public class GenerateUTR30DataFiles { System.err.println("done."); } - private static void download(URL url, String outputFile) throws IOException { - final URLConnection connection = openConnection(url); + private static void download(URI uri, String outputFile) throws IOException { + final URLConnection connection = openConnection(uri.toURL()); try (InputStream inputStream = connection.getInputStream(); OutputStream outputStream = Files.newOutputStream(Path.of(outputFile))) { inputStream.transferTo(outputStream); diff --git a/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/PerfRunData.java b/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/PerfRunData.java index 5c346664bf5..72253d33051 100644 --- a/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/PerfRunData.java +++ b/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/PerfRunData.java @@ -46,6 +46,7 @@ import org.apache.lucene.store.ByteBuffersDirectory; import org.apache.lucene.store.Directory; import org.apache.lucene.store.FSDirectory; import org.apache.lucene.util.IOUtils; +import org.apache.lucene.util.SuppressForbidden; /** * Data maintained by a performance test run. @@ -204,7 +205,7 @@ public class PerfRunData implements Closeable { resetInputs(); // release unused stuff - System.runFinalization(); + runFinalization(); System.gc(); // Re-init clock @@ -482,4 +483,10 @@ public class PerfRunData implements Closeable { public Map getAnalyzerFactories() { return analyzerFactories; } + + @SuppressWarnings("removal") + @SuppressForbidden(reason = "requires to run finalization") + private static void runFinalization() { + System.runFinalization(); + } } diff --git a/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/NewLocaleTask.java b/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/NewLocaleTask.java index cbeab25c52f..e702b7c5415 100644 --- a/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/NewLocaleTask.java +++ b/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/NewLocaleTask.java @@ -39,7 +39,7 @@ public class NewLocaleTask extends PerfTask { private String variant; /** - * Create a new {@link java.util.Locale} and set it it in the getRunData() for use by all future + * Create a new {@link java.util.Locale} and set it in the getRunData() for use by all future * tasks. */ public NewLocaleTask(PerfRunData runData) { @@ -52,7 +52,7 @@ public class NewLocaleTask extends PerfTask { String lang = language; if (lang.equalsIgnoreCase("ROOT")) lang = ""; // empty language is the root locale in the JDK - return new Locale(lang, country, variant); + return Locale.of(lang, country, variant); } @Override diff --git a/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/TestPerfTasksLogic.java b/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/TestPerfTasksLogic.java index 0ded6008ab8..3e80f8ec4a1 100644 --- a/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/TestPerfTasksLogic.java +++ b/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/TestPerfTasksLogic.java @@ -793,19 +793,19 @@ public class TestPerfTasksLogic extends BenchmarkTestCase { // ROOT locale benchmark = execBenchmark(getLocaleConfig("ROOT")); - assertEquals(new Locale(""), benchmark.getRunData().getLocale()); + assertEquals(Locale.of(""), benchmark.getRunData().getLocale()); // specify just a language benchmark = execBenchmark(getLocaleConfig("de")); - assertEquals(new Locale("de"), benchmark.getRunData().getLocale()); + assertEquals(Locale.of("de"), benchmark.getRunData().getLocale()); // specify language + country benchmark = execBenchmark(getLocaleConfig("en,US")); - assertEquals(new Locale("en", "US"), benchmark.getRunData().getLocale()); + assertEquals(Locale.of("en", "US"), benchmark.getRunData().getLocale()); // specify language + country + variant benchmark = execBenchmark(getLocaleConfig("no,NO,NY")); - assertEquals(new Locale("no", "NO", "NY"), benchmark.getRunData().getLocale()); + assertEquals(Locale.of("no", "NO", "NY"), benchmark.getRunData().getLocale()); } private String[] getLocaleConfig(String localeParam) { @@ -832,22 +832,22 @@ public class TestPerfTasksLogic extends BenchmarkTestCase { public void testCollator() throws Exception { // ROOT locale Benchmark benchmark = execBenchmark(getCollatorConfig("ROOT", "impl:jdk")); - CollationKeyAnalyzer expected = new CollationKeyAnalyzer(Collator.getInstance(new Locale(""))); + CollationKeyAnalyzer expected = new CollationKeyAnalyzer(Collator.getInstance(Locale.of(""))); assertEqualCollation(expected, benchmark.getRunData().getAnalyzer(), "foobar"); // specify just a language benchmark = execBenchmark(getCollatorConfig("de", "impl:jdk")); - expected = new CollationKeyAnalyzer(Collator.getInstance(new Locale("de"))); + expected = new CollationKeyAnalyzer(Collator.getInstance(Locale.of("de"))); assertEqualCollation(expected, benchmark.getRunData().getAnalyzer(), "foobar"); // specify language + country benchmark = execBenchmark(getCollatorConfig("en,US", "impl:jdk")); - expected = new CollationKeyAnalyzer(Collator.getInstance(new Locale("en", "US"))); + expected = new CollationKeyAnalyzer(Collator.getInstance(Locale.of("en", "US"))); assertEqualCollation(expected, benchmark.getRunData().getAnalyzer(), "foobar"); // specify language + country + variant benchmark = execBenchmark(getCollatorConfig("no,NO,NY", "impl:jdk")); - expected = new CollationKeyAnalyzer(Collator.getInstance(new Locale("no", "NO", "NY"))); + expected = new CollationKeyAnalyzer(Collator.getInstance(Locale.of("no", "NO", "NY"))); assertEqualCollation(expected, benchmark.getRunData().getAnalyzer(), "foobar"); } diff --git a/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/feeds/TestHtmlParser.java b/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/feeds/TestHtmlParser.java index 9d147832bf4..b7935a73ec6 100644 --- a/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/feeds/TestHtmlParser.java +++ b/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/feeds/TestHtmlParser.java @@ -96,7 +96,7 @@ public class TestHtmlParser extends LuceneTestCase { public void testTurkish() throws Exception { final Locale saved = Locale.getDefault(); try { - Locale.setDefault(new Locale("tr", "TR")); + Locale.setDefault(Locale.of("tr", "TR")); String text = "ııı" + "\"ş\"" diff --git a/lucene/core/src/test/org/apache/lucene/util/TestWeakIdentityMap.java b/lucene/core/src/test/org/apache/lucene/util/TestWeakIdentityMap.java index 3db8540e30a..86098cbe048 100644 --- a/lucene/core/src/test/org/apache/lucene/util/TestWeakIdentityMap.java +++ b/lucene/core/src/test/org/apache/lucene/util/TestWeakIdentityMap.java @@ -119,7 +119,7 @@ public class TestWeakIdentityMap extends LuceneTestCase { int size = map.size(); for (int i = 0; size > 0 && i < 10; i++) try { - System.runFinalization(); + runFinalization(); System.gc(); int newSize = map.size(); assertTrue("previousSize(" + size + ")>=newSize(" + newSize + ")", size >= newSize); @@ -232,7 +232,7 @@ public class TestWeakIdentityMap extends LuceneTestCase { int size = map.size(); for (int i = 0; size > 0 && i < 10; i++) try { - System.runFinalization(); + runFinalization(); System.gc(); int newSize = map.size(); assertTrue("previousSize(" + size + ")>=newSize(" + newSize + ")", size >= newSize); @@ -252,4 +252,10 @@ public class TestWeakIdentityMap extends LuceneTestCase { InterruptedException ie) { } } + + @SuppressWarnings("removal") + @SuppressForbidden(reason = "requires to run finalization") + private static void runFinalization() { + System.runFinalization(); + } } diff --git a/lucene/luke/src/java/org/apache/lucene/luke/app/desktop/components/fragments/search/QueryParserPaneProvider.java b/lucene/luke/src/java/org/apache/lucene/luke/app/desktop/components/fragments/search/QueryParserPaneProvider.java index 4dc585ea461..52aa18d1225 100644 --- a/lucene/luke/src/java/org/apache/lucene/luke/app/desktop/components/fragments/search/QueryParserPaneProvider.java +++ b/lucene/luke/src/java/org/apache/lucene/luke/app/desktop/components/fragments/search/QueryParserPaneProvider.java @@ -421,7 +421,7 @@ public final class QueryParserPaneProvider implements QueryParserTabOperator { .fuzzyMinSim(fuzzyMinSimFloat) .fuzzyPrefixLength(fuzzyPrefLenInt) .dateResolution(DateTools.Resolution.valueOf((String) dateResCB.getSelectedItem())) - .locale(new Locale(locationTF.getText())) + .locale(Locale.of(locationTF.getText())) .timeZone(TimeZone.getTimeZone(timezoneTF.getText())) .typeMap(typeMap) .build(); diff --git a/lucene/luke/src/java/org/apache/lucene/luke/app/desktop/util/URLLabel.java b/lucene/luke/src/java/org/apache/lucene/luke/app/desktop/util/URLLabel.java index 51e188e9af5..e4f759b3095 100644 --- a/lucene/luke/src/java/org/apache/lucene/luke/app/desktop/util/URLLabel.java +++ b/lucene/luke/src/java/org/apache/lucene/luke/app/desktop/util/URLLabel.java @@ -23,6 +23,7 @@ import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.io.IOException; import java.net.MalformedURLException; +import java.net.URI; import java.net.URISyntaxException; import java.net.URL; import javax.swing.JLabel; @@ -37,7 +38,7 @@ public final class URLLabel extends JLabel { super(text); try { - this.link = new URL(text); + this.link = (URI.create(text)).toURL(); } catch (MalformedURLException e) { throw new LukeException(e.getMessage(), e); } diff --git a/lucene/queryparser/src/test/org/apache/lucene/queryparser/flexible/messages/TestNLS.java b/lucene/queryparser/src/test/org/apache/lucene/queryparser/flexible/messages/TestNLS.java index ba6b4131f14..833e4460d53 100644 --- a/lucene/queryparser/src/test/org/apache/lucene/queryparser/flexible/messages/TestNLS.java +++ b/lucene/queryparser/src/test/org/apache/lucene/queryparser/flexible/messages/TestNLS.java @@ -68,7 +68,7 @@ public class TestNLS extends LuceneTestCase { } public void testNLSLoading_xx_XX() { - Locale locale = new Locale("xx", "XX", ""); + Locale locale = Locale.of("xx", "XX", ""); String message = NLS.getLocalizedMessage( MessagesTestBundle.Q0004E_INVALID_SYNTAX_ESCAPE_UNICODE_TRUNCATION, locale); From 0343e17fb78da7a627d07b2a2cda42ac0e7d9041 Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Fri, 3 Nov 2023 11:44:03 -0400 Subject: [PATCH 02/23] use language tags everywhere for Locales --- .../lucene/analysis/br/BrazilianStemmer.java | 2 +- .../lucene/analysis/de/GermanStemmer.java | 2 +- .../lucene/analysis/th/ThaiTokenizer.java | 3 ++- .../collation/TestCollationKeyAnalyzer.java | 2 +- .../icu/TestICUCollationKeyAnalyzer.java | 2 +- .../benchmark/byTask/tasks/NewLocaleTask.java | 19 ++++++++++++++++--- .../benchmark/byTask/TestPerfTasksLogic.java | 8 ++++---- .../byTask/feeds/TestHtmlParser.java | 2 +- .../search/QueryParserPaneProvider.java | 2 +- .../flexible/messages/TestNLS.java | 2 +- 10 files changed, 29 insertions(+), 15 deletions(-) diff --git a/lucene/analysis/common/src/java/org/apache/lucene/analysis/br/BrazilianStemmer.java b/lucene/analysis/common/src/java/org/apache/lucene/analysis/br/BrazilianStemmer.java index c4106edefd1..5dbeb77a705 100644 --- a/lucene/analysis/common/src/java/org/apache/lucene/analysis/br/BrazilianStemmer.java +++ b/lucene/analysis/common/src/java/org/apache/lucene/analysis/br/BrazilianStemmer.java @@ -20,7 +20,7 @@ import java.util.Locale; /** A stemmer for Brazilian Portuguese words. */ class BrazilianStemmer { - private static final Locale locale = Locale.of("pt", "BR"); + private static final Locale locale = Locale.forLanguageTag("pt-BR"); /** Changed term */ private String TERM; diff --git a/lucene/analysis/common/src/java/org/apache/lucene/analysis/de/GermanStemmer.java b/lucene/analysis/common/src/java/org/apache/lucene/analysis/de/GermanStemmer.java index 3d4b1908db8..763871357fb 100644 --- a/lucene/analysis/common/src/java/org/apache/lucene/analysis/de/GermanStemmer.java +++ b/lucene/analysis/common/src/java/org/apache/lucene/analysis/de/GermanStemmer.java @@ -33,7 +33,7 @@ class GermanStemmer { /** Amount of characters that are removed with substitute() while stemming. */ private int substCount = 0; - private static final Locale locale = Locale.of("de", "DE"); + private static final Locale locale = Locale.forLanguageTag("de-DE"); /** * Stemms the given term to an unique discriminator. diff --git a/lucene/analysis/common/src/java/org/apache/lucene/analysis/th/ThaiTokenizer.java b/lucene/analysis/common/src/java/org/apache/lucene/analysis/th/ThaiTokenizer.java index e6e933a1fba..9ae12316d40 100644 --- a/lucene/analysis/common/src/java/org/apache/lucene/analysis/th/ThaiTokenizer.java +++ b/lucene/analysis/common/src/java/org/apache/lucene/analysis/th/ThaiTokenizer.java @@ -38,7 +38,8 @@ public class ThaiTokenizer extends SegmentingTokenizerBase { */ public static final boolean DBBI_AVAILABLE; - private static final BreakIterator proto = BreakIterator.getWordInstance(Locale.of("th")); + private static final BreakIterator proto = + BreakIterator.getWordInstance(Locale.forLanguageTag("th")); static { // check that we have a working dictionary-based break iterator for thai diff --git a/lucene/analysis/common/src/test/org/apache/lucene/collation/TestCollationKeyAnalyzer.java b/lucene/analysis/common/src/test/org/apache/lucene/collation/TestCollationKeyAnalyzer.java index f74e2a7bdd8..19dc7a14afc 100644 --- a/lucene/analysis/common/src/test/org/apache/lucene/collation/TestCollationKeyAnalyzer.java +++ b/lucene/analysis/common/src/test/org/apache/lucene/collation/TestCollationKeyAnalyzer.java @@ -26,7 +26,7 @@ public class TestCollationKeyAnalyzer extends CollationTestBase { // Neither Java 1.4.2 nor 1.5.0 has Farsi Locale collation available in // RuleBasedCollator. However, the Arabic Locale seems to order the Farsi // characters properly. - private Collator collator = Collator.getInstance(Locale.of("ar")); + private Collator collator = Collator.getInstance(Locale.forLanguageTag("ar")); private Analyzer analyzer; @Override diff --git a/lucene/analysis/icu/src/test/org/apache/lucene/analysis/icu/TestICUCollationKeyAnalyzer.java b/lucene/analysis/icu/src/test/org/apache/lucene/analysis/icu/TestICUCollationKeyAnalyzer.java index 0b49005176e..aa5acf33bc7 100644 --- a/lucene/analysis/icu/src/test/org/apache/lucene/analysis/icu/TestICUCollationKeyAnalyzer.java +++ b/lucene/analysis/icu/src/test/org/apache/lucene/analysis/icu/TestICUCollationKeyAnalyzer.java @@ -24,7 +24,7 @@ import org.apache.lucene.util.BytesRef; public class TestICUCollationKeyAnalyzer extends CollationTestBase { - private Collator collator = Collator.getInstance(Locale.of("fa")); + private Collator collator = Collator.getInstance(Locale.forLanguageTag("fa")); private Analyzer analyzer; @Override diff --git a/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/NewLocaleTask.java b/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/NewLocaleTask.java index e702b7c5415..5bc2ea856fe 100644 --- a/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/NewLocaleTask.java +++ b/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/NewLocaleTask.java @@ -49,10 +49,23 @@ public class NewLocaleTask extends PerfTask { static Locale createLocale(String language, String country, String variant) { if (language == null || language.length() == 0) return null; - String lang = language; - if (lang.equalsIgnoreCase("ROOT")) lang = ""; // empty language is the root locale in the JDK + if (language.equalsIgnoreCase("ROOT")) { + return Locale.ROOT; + } - return Locale.of(lang, country, variant); + StringBuilder sb = new StringBuilder(); + sb.append(language); + if (country.length() > 0) { + sb.append('-'); + sb.append(country); + + if (variant.length() > 0) { + sb.append('-'); + sb.append(variant); + } + } + + return Locale.forLanguageTag(sb.toString()); } @Override diff --git a/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/TestPerfTasksLogic.java b/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/TestPerfTasksLogic.java index 3e80f8ec4a1..d637ee4f4a1 100644 --- a/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/TestPerfTasksLogic.java +++ b/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/TestPerfTasksLogic.java @@ -793,19 +793,19 @@ public class TestPerfTasksLogic extends BenchmarkTestCase { // ROOT locale benchmark = execBenchmark(getLocaleConfig("ROOT")); - assertEquals(Locale.of(""), benchmark.getRunData().getLocale()); + assertEquals(Locale.ROOT, benchmark.getRunData().getLocale()); // specify just a language benchmark = execBenchmark(getLocaleConfig("de")); - assertEquals(Locale.of("de"), benchmark.getRunData().getLocale()); + assertEquals(Locale.forLanguageTag("de"), benchmark.getRunData().getLocale()); // specify language + country benchmark = execBenchmark(getLocaleConfig("en,US")); - assertEquals(Locale.of("en", "US"), benchmark.getRunData().getLocale()); + assertEquals(Locale.forLanguageTag("en-US"), benchmark.getRunData().getLocale()); // specify language + country + variant benchmark = execBenchmark(getLocaleConfig("no,NO,NY")); - assertEquals(Locale.of("no", "NO", "NY"), benchmark.getRunData().getLocale()); + assertEquals(Locale.forLanguageTag("no-NO-NY"), benchmark.getRunData().getLocale()); } private String[] getLocaleConfig(String localeParam) { diff --git a/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/feeds/TestHtmlParser.java b/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/feeds/TestHtmlParser.java index b7935a73ec6..57639a69f74 100644 --- a/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/feeds/TestHtmlParser.java +++ b/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/feeds/TestHtmlParser.java @@ -96,7 +96,7 @@ public class TestHtmlParser extends LuceneTestCase { public void testTurkish() throws Exception { final Locale saved = Locale.getDefault(); try { - Locale.setDefault(Locale.of("tr", "TR")); + Locale.setDefault(Locale.forLanguageTag("tr-TR")); String text = "ııı" + "\"ş\"" diff --git a/lucene/luke/src/java/org/apache/lucene/luke/app/desktop/components/fragments/search/QueryParserPaneProvider.java b/lucene/luke/src/java/org/apache/lucene/luke/app/desktop/components/fragments/search/QueryParserPaneProvider.java index 52aa18d1225..4299aaf0346 100644 --- a/lucene/luke/src/java/org/apache/lucene/luke/app/desktop/components/fragments/search/QueryParserPaneProvider.java +++ b/lucene/luke/src/java/org/apache/lucene/luke/app/desktop/components/fragments/search/QueryParserPaneProvider.java @@ -421,7 +421,7 @@ public final class QueryParserPaneProvider implements QueryParserTabOperator { .fuzzyMinSim(fuzzyMinSimFloat) .fuzzyPrefixLength(fuzzyPrefLenInt) .dateResolution(DateTools.Resolution.valueOf((String) dateResCB.getSelectedItem())) - .locale(Locale.of(locationTF.getText())) + .locale(Locale.forLanguageTag(locationTF.getText())) .timeZone(TimeZone.getTimeZone(timezoneTF.getText())) .typeMap(typeMap) .build(); diff --git a/lucene/queryparser/src/test/org/apache/lucene/queryparser/flexible/messages/TestNLS.java b/lucene/queryparser/src/test/org/apache/lucene/queryparser/flexible/messages/TestNLS.java index 833e4460d53..486bdefa366 100644 --- a/lucene/queryparser/src/test/org/apache/lucene/queryparser/flexible/messages/TestNLS.java +++ b/lucene/queryparser/src/test/org/apache/lucene/queryparser/flexible/messages/TestNLS.java @@ -68,7 +68,7 @@ public class TestNLS extends LuceneTestCase { } public void testNLSLoading_xx_XX() { - Locale locale = Locale.of("xx", "XX", ""); + Locale locale = Locale.forLanguageTag("xx-XX"); String message = NLS.getLocalizedMessage( MessagesTestBundle.Q0004E_INVALID_SYNTAX_ESCAPE_UNICODE_TRUNCATION, locale); From bc4f27d6d01130a2b270ed6514936714caf9698e Mon Sep 17 00:00:00 2001 From: ChrisHegarty Date: Fri, 3 Nov 2023 15:56:33 +0000 Subject: [PATCH 03/23] more language tags --- .../lucene/benchmark/byTask/TestPerfTasksLogic.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/TestPerfTasksLogic.java b/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/TestPerfTasksLogic.java index d637ee4f4a1..c956dd97f9c 100644 --- a/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/TestPerfTasksLogic.java +++ b/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/TestPerfTasksLogic.java @@ -832,22 +832,22 @@ public class TestPerfTasksLogic extends BenchmarkTestCase { public void testCollator() throws Exception { // ROOT locale Benchmark benchmark = execBenchmark(getCollatorConfig("ROOT", "impl:jdk")); - CollationKeyAnalyzer expected = new CollationKeyAnalyzer(Collator.getInstance(Locale.of(""))); + CollationKeyAnalyzer expected = new CollationKeyAnalyzer(Collator.getInstance(Locale.forLanguageTag(""))); assertEqualCollation(expected, benchmark.getRunData().getAnalyzer(), "foobar"); // specify just a language benchmark = execBenchmark(getCollatorConfig("de", "impl:jdk")); - expected = new CollationKeyAnalyzer(Collator.getInstance(Locale.of("de"))); + expected = new CollationKeyAnalyzer(Collator.getInstance(Locale.forLanguageTag("de"))); assertEqualCollation(expected, benchmark.getRunData().getAnalyzer(), "foobar"); // specify language + country benchmark = execBenchmark(getCollatorConfig("en,US", "impl:jdk")); - expected = new CollationKeyAnalyzer(Collator.getInstance(Locale.of("en", "US"))); + expected = new CollationKeyAnalyzer(Collator.getInstance(Locale.forLanguageTag("en-US"))); assertEqualCollation(expected, benchmark.getRunData().getAnalyzer(), "foobar"); // specify language + country + variant benchmark = execBenchmark(getCollatorConfig("no,NO,NY", "impl:jdk")); - expected = new CollationKeyAnalyzer(Collator.getInstance(Locale.of("no", "NO", "NY"))); + expected = new CollationKeyAnalyzer(Collator.getInstance(Locale.forLanguageTag("no-NO-NY"))); assertEqualCollation(expected, benchmark.getRunData().getAnalyzer(), "foobar"); } From 4a49d417a7e5b6f5f13026d022bd2bbe3cc08958 Mon Sep 17 00:00:00 2001 From: ChrisHegarty Date: Fri, 3 Nov 2023 16:05:54 +0000 Subject: [PATCH 04/23] bump GH actions --- .github/workflows/distribution.yml | 2 +- .github/workflows/gradle-precommit.yml | 2 +- .github/workflows/hunspell.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/distribution.yml b/.github/workflows/distribution.yml index 3ed199888d5..1c2b39cbed1 100644 --- a/.github/workflows/distribution.yml +++ b/.github/workflows/distribution.yml @@ -35,7 +35,7 @@ jobs: uses: actions/setup-java@v3 with: distribution: 'temurin' - java-version: 17 + java-version: 21 java-package: jdk - name: Prepare caches uses: ./.github/actions/gradle-caches diff --git a/.github/workflows/gradle-precommit.yml b/.github/workflows/gradle-precommit.yml index 076fb0e095a..c6b5dfe38db 100644 --- a/.github/workflows/gradle-precommit.yml +++ b/.github/workflows/gradle-precommit.yml @@ -25,7 +25,7 @@ jobs: # Operating systems to run on. os: [ubuntu-latest] # Test JVMs. - java: [ '17' ] + java: [ '21' ] env: GRADLE_ENTERPRISE_ACCESS_KEY: ${{ secrets.GE_ACCESS_TOKEN }} diff --git a/.github/workflows/hunspell.yml b/.github/workflows/hunspell.yml index ed040ec13c5..f44e2ea919e 100644 --- a/.github/workflows/hunspell.yml +++ b/.github/workflows/hunspell.yml @@ -25,7 +25,7 @@ jobs: uses: actions/setup-java@v3 with: distribution: 'temurin' - java-version: 17 + java-version: 21 java-package: jdk - name: Prepare caches From d2cdf238f3f7286c09871a507cb66f35fe3a2cbc Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Fri, 3 Nov 2023 12:27:02 -0400 Subject: [PATCH 05/23] use a pickier forLanguageTag --- .../lucene/analysis/br/BrazilianStemmer.java | 2 +- .../lucene/analysis/de/GermanStemmer.java | 2 +- .../lucene/analysis/th/ThaiTokenizer.java | 2 +- .../collation/TestCollationKeyAnalyzer.java | 2 +- .../icu/TestICUCollationKeyAnalyzer.java | 2 +- .../benchmark/byTask/tasks/NewLocaleTask.java | 2 +- .../benchmark/byTask/TestPerfTasksLogic.java | 22 +++++++++++++------ .../byTask/feeds/TestHtmlParser.java | 2 +- .../search/QueryParserPaneProvider.java | 2 +- .../flexible/messages/TestNLS.java | 2 +- 10 files changed, 24 insertions(+), 16 deletions(-) diff --git a/lucene/analysis/common/src/java/org/apache/lucene/analysis/br/BrazilianStemmer.java b/lucene/analysis/common/src/java/org/apache/lucene/analysis/br/BrazilianStemmer.java index 5dbeb77a705..508506f5633 100644 --- a/lucene/analysis/common/src/java/org/apache/lucene/analysis/br/BrazilianStemmer.java +++ b/lucene/analysis/common/src/java/org/apache/lucene/analysis/br/BrazilianStemmer.java @@ -20,7 +20,7 @@ import java.util.Locale; /** A stemmer for Brazilian Portuguese words. */ class BrazilianStemmer { - private static final Locale locale = Locale.forLanguageTag("pt-BR"); + private static final Locale locale = Locale.Builder().setLanguageTag("pt-BR").build(); /** Changed term */ private String TERM; diff --git a/lucene/analysis/common/src/java/org/apache/lucene/analysis/de/GermanStemmer.java b/lucene/analysis/common/src/java/org/apache/lucene/analysis/de/GermanStemmer.java index 763871357fb..1244d057432 100644 --- a/lucene/analysis/common/src/java/org/apache/lucene/analysis/de/GermanStemmer.java +++ b/lucene/analysis/common/src/java/org/apache/lucene/analysis/de/GermanStemmer.java @@ -33,7 +33,7 @@ class GermanStemmer { /** Amount of characters that are removed with substitute() while stemming. */ private int substCount = 0; - private static final Locale locale = Locale.forLanguageTag("de-DE"); + private static final Locale locale = Locale.Builder().setLanguageTag("de-DE").build(); /** * Stemms the given term to an unique discriminator. diff --git a/lucene/analysis/common/src/java/org/apache/lucene/analysis/th/ThaiTokenizer.java b/lucene/analysis/common/src/java/org/apache/lucene/analysis/th/ThaiTokenizer.java index 9ae12316d40..9c3dafbdcee 100644 --- a/lucene/analysis/common/src/java/org/apache/lucene/analysis/th/ThaiTokenizer.java +++ b/lucene/analysis/common/src/java/org/apache/lucene/analysis/th/ThaiTokenizer.java @@ -39,7 +39,7 @@ public class ThaiTokenizer extends SegmentingTokenizerBase { public static final boolean DBBI_AVAILABLE; private static final BreakIterator proto = - BreakIterator.getWordInstance(Locale.forLanguageTag("th")); + BreakIterator.getWordInstance(Locale.Builder().setLanguageTag("th").build()); static { // check that we have a working dictionary-based break iterator for thai diff --git a/lucene/analysis/common/src/test/org/apache/lucene/collation/TestCollationKeyAnalyzer.java b/lucene/analysis/common/src/test/org/apache/lucene/collation/TestCollationKeyAnalyzer.java index 19dc7a14afc..a5e3492b08c 100644 --- a/lucene/analysis/common/src/test/org/apache/lucene/collation/TestCollationKeyAnalyzer.java +++ b/lucene/analysis/common/src/test/org/apache/lucene/collation/TestCollationKeyAnalyzer.java @@ -26,7 +26,7 @@ public class TestCollationKeyAnalyzer extends CollationTestBase { // Neither Java 1.4.2 nor 1.5.0 has Farsi Locale collation available in // RuleBasedCollator. However, the Arabic Locale seems to order the Farsi // characters properly. - private Collator collator = Collator.getInstance(Locale.forLanguageTag("ar")); + private Collator collator = Collator.getInstance(Locale.Builder().setLanguageTag("ar").build()); private Analyzer analyzer; @Override diff --git a/lucene/analysis/icu/src/test/org/apache/lucene/analysis/icu/TestICUCollationKeyAnalyzer.java b/lucene/analysis/icu/src/test/org/apache/lucene/analysis/icu/TestICUCollationKeyAnalyzer.java index aa5acf33bc7..08a43f19d56 100644 --- a/lucene/analysis/icu/src/test/org/apache/lucene/analysis/icu/TestICUCollationKeyAnalyzer.java +++ b/lucene/analysis/icu/src/test/org/apache/lucene/analysis/icu/TestICUCollationKeyAnalyzer.java @@ -24,7 +24,7 @@ import org.apache.lucene.util.BytesRef; public class TestICUCollationKeyAnalyzer extends CollationTestBase { - private Collator collator = Collator.getInstance(Locale.forLanguageTag("fa")); + private Collator collator = Collator.getInstance(Locale.Builder().setLanguageTag("fa").build()); private Analyzer analyzer; @Override diff --git a/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/NewLocaleTask.java b/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/NewLocaleTask.java index 5bc2ea856fe..077e2dd17e4 100644 --- a/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/NewLocaleTask.java +++ b/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/NewLocaleTask.java @@ -65,7 +65,7 @@ public class NewLocaleTask extends PerfTask { } } - return Locale.forLanguageTag(sb.toString()); + return Locale.Builder().setLanguageTag(sb.toString()).build(); } @Override diff --git a/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/TestPerfTasksLogic.java b/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/TestPerfTasksLogic.java index c956dd97f9c..c35676e4d7a 100644 --- a/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/TestPerfTasksLogic.java +++ b/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/TestPerfTasksLogic.java @@ -797,15 +797,17 @@ public class TestPerfTasksLogic extends BenchmarkTestCase { // specify just a language benchmark = execBenchmark(getLocaleConfig("de")); - assertEquals(Locale.forLanguageTag("de"), benchmark.getRunData().getLocale()); + assertEquals(Locale.Builder().setLanguageTag("de").build(), benchmark.getRunData().getLocale()); // specify language + country benchmark = execBenchmark(getLocaleConfig("en,US")); - assertEquals(Locale.forLanguageTag("en-US"), benchmark.getRunData().getLocale()); + assertEquals( + Locale.Builder().setLanguageTag("en-US").build(), benchmark.getRunData().getLocale()); // specify language + country + variant benchmark = execBenchmark(getLocaleConfig("no,NO,NY")); - assertEquals(Locale.forLanguageTag("no-NO-NY"), benchmark.getRunData().getLocale()); + assertEquals( + Locale.Builder().setLanguageTag("no-NO-NY").build(), benchmark.getRunData().getLocale()); } private String[] getLocaleConfig(String localeParam) { @@ -832,22 +834,28 @@ public class TestPerfTasksLogic extends BenchmarkTestCase { public void testCollator() throws Exception { // ROOT locale Benchmark benchmark = execBenchmark(getCollatorConfig("ROOT", "impl:jdk")); - CollationKeyAnalyzer expected = new CollationKeyAnalyzer(Collator.getInstance(Locale.forLanguageTag(""))); + CollationKeyAnalyzer expected = new CollationKeyAnalyzer(Collator.getInstance(Locale.ROOT)); assertEqualCollation(expected, benchmark.getRunData().getAnalyzer(), "foobar"); // specify just a language benchmark = execBenchmark(getCollatorConfig("de", "impl:jdk")); - expected = new CollationKeyAnalyzer(Collator.getInstance(Locale.forLanguageTag("de"))); + expected = + new CollationKeyAnalyzer( + Collator.getInstance(Locale.Builder().setLanguageTag("de").build())); assertEqualCollation(expected, benchmark.getRunData().getAnalyzer(), "foobar"); // specify language + country benchmark = execBenchmark(getCollatorConfig("en,US", "impl:jdk")); - expected = new CollationKeyAnalyzer(Collator.getInstance(Locale.forLanguageTag("en-US"))); + expected = + new CollationKeyAnalyzer( + Collator.getInstance(Locale.Builder().setLanguageTag("en-US").build())); assertEqualCollation(expected, benchmark.getRunData().getAnalyzer(), "foobar"); // specify language + country + variant benchmark = execBenchmark(getCollatorConfig("no,NO,NY", "impl:jdk")); - expected = new CollationKeyAnalyzer(Collator.getInstance(Locale.forLanguageTag("no-NO-NY"))); + expected = + new CollationKeyAnalyzer( + Collator.getInstance(Locale.Builder().setLanguageTag("no-NO-NY").build())); assertEqualCollation(expected, benchmark.getRunData().getAnalyzer(), "foobar"); } diff --git a/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/feeds/TestHtmlParser.java b/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/feeds/TestHtmlParser.java index 57639a69f74..d9c619d6488 100644 --- a/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/feeds/TestHtmlParser.java +++ b/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/feeds/TestHtmlParser.java @@ -96,7 +96,7 @@ public class TestHtmlParser extends LuceneTestCase { public void testTurkish() throws Exception { final Locale saved = Locale.getDefault(); try { - Locale.setDefault(Locale.forLanguageTag("tr-TR")); + Locale.setDefault(Locale.Builder().setLanguageTag("tr-TR").build()); String text = "ııı" + "\"ş\"" diff --git a/lucene/luke/src/java/org/apache/lucene/luke/app/desktop/components/fragments/search/QueryParserPaneProvider.java b/lucene/luke/src/java/org/apache/lucene/luke/app/desktop/components/fragments/search/QueryParserPaneProvider.java index 4299aaf0346..0448611da4d 100644 --- a/lucene/luke/src/java/org/apache/lucene/luke/app/desktop/components/fragments/search/QueryParserPaneProvider.java +++ b/lucene/luke/src/java/org/apache/lucene/luke/app/desktop/components/fragments/search/QueryParserPaneProvider.java @@ -421,7 +421,7 @@ public final class QueryParserPaneProvider implements QueryParserTabOperator { .fuzzyMinSim(fuzzyMinSimFloat) .fuzzyPrefixLength(fuzzyPrefLenInt) .dateResolution(DateTools.Resolution.valueOf((String) dateResCB.getSelectedItem())) - .locale(Locale.forLanguageTag(locationTF.getText())) + .locale(Locale.Builder().setLanguageTag(locationTF.getText()).build()) .timeZone(TimeZone.getTimeZone(timezoneTF.getText())) .typeMap(typeMap) .build(); diff --git a/lucene/queryparser/src/test/org/apache/lucene/queryparser/flexible/messages/TestNLS.java b/lucene/queryparser/src/test/org/apache/lucene/queryparser/flexible/messages/TestNLS.java index 486bdefa366..af285a821b5 100644 --- a/lucene/queryparser/src/test/org/apache/lucene/queryparser/flexible/messages/TestNLS.java +++ b/lucene/queryparser/src/test/org/apache/lucene/queryparser/flexible/messages/TestNLS.java @@ -68,7 +68,7 @@ public class TestNLS extends LuceneTestCase { } public void testNLSLoading_xx_XX() { - Locale locale = Locale.forLanguageTag("xx-XX"); + Locale locale = Locale.Builder().setLanguageTag("xx-XX").build(); String message = NLS.getLocalizedMessage( MessagesTestBundle.Q0004E_INVALID_SYNTAX_ESCAPE_UNICODE_TRUNCATION, locale); From 27abd1934d95d88b9188658032de23c5bfcec0a2 Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Fri, 3 Nov 2023 12:30:39 -0400 Subject: [PATCH 06/23] fix wrong advice from forbidden APIs :) --- gradle/validation/forbidden-apis/defaults.all.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle/validation/forbidden-apis/defaults.all.txt b/gradle/validation/forbidden-apis/defaults.all.txt index 0c67167aaf7..7d99ebb1da0 100644 --- a/gradle/validation/forbidden-apis/defaults.all.txt +++ b/gradle/validation/forbidden-apis/defaults.all.txt @@ -43,7 +43,7 @@ java.util.Vector @ Use more modern java.util.ArrayList as it is not synchronized # TODO (needs some fix in forbiddenapis): this also hits java.util.Properties: # java.util.Hashtable @ Use more modern java.util.HashMap as it is not synchronized -java.util.Locale#forLanguageTag(java.lang.String) @ use new Locale.Builder().setLanguageTag(...).build() which has error handling +java.util.Locale#forLanguageTag(java.lang.String) @ use new Locale.Builder.setLanguageTag(...).build() which has error handling java.util.Locale#toString() @ use Locale#toLanguageTag() for a standardized BCP47 locale name @defaultMessage Constructors for wrapper classes of Java primitives should be avoided in favor of the public static methods available or autoboxing From 5a1cdbe2ef1cb0b25700e9c86921e3d19e1bfd96 Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Fri, 3 Nov 2023 12:32:02 -0400 Subject: [PATCH 07/23] Revert "fix wrong advice from forbidden APIs :)" This reverts commit 27abd1934d95d88b9188658032de23c5bfcec0a2. --- gradle/validation/forbidden-apis/defaults.all.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle/validation/forbidden-apis/defaults.all.txt b/gradle/validation/forbidden-apis/defaults.all.txt index 7d99ebb1da0..0c67167aaf7 100644 --- a/gradle/validation/forbidden-apis/defaults.all.txt +++ b/gradle/validation/forbidden-apis/defaults.all.txt @@ -43,7 +43,7 @@ java.util.Vector @ Use more modern java.util.ArrayList as it is not synchronized # TODO (needs some fix in forbiddenapis): this also hits java.util.Properties: # java.util.Hashtable @ Use more modern java.util.HashMap as it is not synchronized -java.util.Locale#forLanguageTag(java.lang.String) @ use new Locale.Builder.setLanguageTag(...).build() which has error handling +java.util.Locale#forLanguageTag(java.lang.String) @ use new Locale.Builder().setLanguageTag(...).build() which has error handling java.util.Locale#toString() @ use Locale#toLanguageTag() for a standardized BCP47 locale name @defaultMessage Constructors for wrapper classes of Java primitives should be avoided in favor of the public static methods available or autoboxing From f1c133e8e00ab6d4b56c591d81df2a0c94ebc88d Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Fri, 3 Nov 2023 12:35:19 -0400 Subject: [PATCH 08/23] make that java as wordy as possible the way it likes it --- .../lucene/analysis/br/BrazilianStemmer.java | 2 +- .../apache/lucene/analysis/de/GermanStemmer.java | 2 +- .../apache/lucene/analysis/th/ThaiTokenizer.java | 2 +- .../lucene/collation/TestCollationKeyAnalyzer.java | 3 ++- .../analysis/icu/TestICUCollationKeyAnalyzer.java | 3 ++- .../benchmark/byTask/tasks/NewLocaleTask.java | 2 +- .../benchmark/byTask/TestPerfTasksLogic.java | 14 ++++++++------ .../benchmark/byTask/feeds/TestHtmlParser.java | 2 +- .../fragments/search/QueryParserPaneProvider.java | 2 +- .../queryparser/flexible/messages/TestNLS.java | 2 +- 10 files changed, 19 insertions(+), 15 deletions(-) diff --git a/lucene/analysis/common/src/java/org/apache/lucene/analysis/br/BrazilianStemmer.java b/lucene/analysis/common/src/java/org/apache/lucene/analysis/br/BrazilianStemmer.java index 508506f5633..f999c25133f 100644 --- a/lucene/analysis/common/src/java/org/apache/lucene/analysis/br/BrazilianStemmer.java +++ b/lucene/analysis/common/src/java/org/apache/lucene/analysis/br/BrazilianStemmer.java @@ -20,7 +20,7 @@ import java.util.Locale; /** A stemmer for Brazilian Portuguese words. */ class BrazilianStemmer { - private static final Locale locale = Locale.Builder().setLanguageTag("pt-BR").build(); + private static final Locale locale = new Locale.Builder().setLanguageTag("pt-BR").build(); /** Changed term */ private String TERM; diff --git a/lucene/analysis/common/src/java/org/apache/lucene/analysis/de/GermanStemmer.java b/lucene/analysis/common/src/java/org/apache/lucene/analysis/de/GermanStemmer.java index 1244d057432..866b160df87 100644 --- a/lucene/analysis/common/src/java/org/apache/lucene/analysis/de/GermanStemmer.java +++ b/lucene/analysis/common/src/java/org/apache/lucene/analysis/de/GermanStemmer.java @@ -33,7 +33,7 @@ class GermanStemmer { /** Amount of characters that are removed with substitute() while stemming. */ private int substCount = 0; - private static final Locale locale = Locale.Builder().setLanguageTag("de-DE").build(); + private static final Locale locale = new Locale.Builder().setLanguageTag("de-DE").build(); /** * Stemms the given term to an unique discriminator. diff --git a/lucene/analysis/common/src/java/org/apache/lucene/analysis/th/ThaiTokenizer.java b/lucene/analysis/common/src/java/org/apache/lucene/analysis/th/ThaiTokenizer.java index 9c3dafbdcee..50674f1f657 100644 --- a/lucene/analysis/common/src/java/org/apache/lucene/analysis/th/ThaiTokenizer.java +++ b/lucene/analysis/common/src/java/org/apache/lucene/analysis/th/ThaiTokenizer.java @@ -39,7 +39,7 @@ public class ThaiTokenizer extends SegmentingTokenizerBase { public static final boolean DBBI_AVAILABLE; private static final BreakIterator proto = - BreakIterator.getWordInstance(Locale.Builder().setLanguageTag("th").build()); + BreakIterator.getWordInstance(new Locale.Builder().setLanguageTag("th").build()); static { // check that we have a working dictionary-based break iterator for thai diff --git a/lucene/analysis/common/src/test/org/apache/lucene/collation/TestCollationKeyAnalyzer.java b/lucene/analysis/common/src/test/org/apache/lucene/collation/TestCollationKeyAnalyzer.java index a5e3492b08c..b76c1d0d07b 100644 --- a/lucene/analysis/common/src/test/org/apache/lucene/collation/TestCollationKeyAnalyzer.java +++ b/lucene/analysis/common/src/test/org/apache/lucene/collation/TestCollationKeyAnalyzer.java @@ -26,7 +26,8 @@ public class TestCollationKeyAnalyzer extends CollationTestBase { // Neither Java 1.4.2 nor 1.5.0 has Farsi Locale collation available in // RuleBasedCollator. However, the Arabic Locale seems to order the Farsi // characters properly. - private Collator collator = Collator.getInstance(Locale.Builder().setLanguageTag("ar").build()); + private Collator collator = + Collator.getInstance(new Locale.Builder().setLanguageTag("ar").build()); private Analyzer analyzer; @Override diff --git a/lucene/analysis/icu/src/test/org/apache/lucene/analysis/icu/TestICUCollationKeyAnalyzer.java b/lucene/analysis/icu/src/test/org/apache/lucene/analysis/icu/TestICUCollationKeyAnalyzer.java index 08a43f19d56..fa867e28ae9 100644 --- a/lucene/analysis/icu/src/test/org/apache/lucene/analysis/icu/TestICUCollationKeyAnalyzer.java +++ b/lucene/analysis/icu/src/test/org/apache/lucene/analysis/icu/TestICUCollationKeyAnalyzer.java @@ -24,7 +24,8 @@ import org.apache.lucene.util.BytesRef; public class TestICUCollationKeyAnalyzer extends CollationTestBase { - private Collator collator = Collator.getInstance(Locale.Builder().setLanguageTag("fa").build()); + private Collator collator = + Collator.getInstance(new Locale.Builder().setLanguageTag("fa").build()); private Analyzer analyzer; @Override diff --git a/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/NewLocaleTask.java b/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/NewLocaleTask.java index 077e2dd17e4..bdd2224555c 100644 --- a/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/NewLocaleTask.java +++ b/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/NewLocaleTask.java @@ -65,7 +65,7 @@ public class NewLocaleTask extends PerfTask { } } - return Locale.Builder().setLanguageTag(sb.toString()).build(); + return new Locale.Builder().setLanguageTag(sb.toString()).build(); } @Override diff --git a/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/TestPerfTasksLogic.java b/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/TestPerfTasksLogic.java index c35676e4d7a..44885ec54b9 100644 --- a/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/TestPerfTasksLogic.java +++ b/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/TestPerfTasksLogic.java @@ -797,17 +797,19 @@ public class TestPerfTasksLogic extends BenchmarkTestCase { // specify just a language benchmark = execBenchmark(getLocaleConfig("de")); - assertEquals(Locale.Builder().setLanguageTag("de").build(), benchmark.getRunData().getLocale()); + assertEquals( + new Locale.Builder().setLanguageTag("de").build(), benchmark.getRunData().getLocale()); // specify language + country benchmark = execBenchmark(getLocaleConfig("en,US")); assertEquals( - Locale.Builder().setLanguageTag("en-US").build(), benchmark.getRunData().getLocale()); + new Locale.Builder().setLanguageTag("en-US").build(), benchmark.getRunData().getLocale()); // specify language + country + variant benchmark = execBenchmark(getLocaleConfig("no,NO,NY")); assertEquals( - Locale.Builder().setLanguageTag("no-NO-NY").build(), benchmark.getRunData().getLocale()); + new Locale.Builder().setLanguageTag("no-NO-NY").build(), + benchmark.getRunData().getLocale()); } private String[] getLocaleConfig(String localeParam) { @@ -841,21 +843,21 @@ public class TestPerfTasksLogic extends BenchmarkTestCase { benchmark = execBenchmark(getCollatorConfig("de", "impl:jdk")); expected = new CollationKeyAnalyzer( - Collator.getInstance(Locale.Builder().setLanguageTag("de").build())); + Collator.getInstance(new Locale.Builder().setLanguageTag("de").build())); assertEqualCollation(expected, benchmark.getRunData().getAnalyzer(), "foobar"); // specify language + country benchmark = execBenchmark(getCollatorConfig("en,US", "impl:jdk")); expected = new CollationKeyAnalyzer( - Collator.getInstance(Locale.Builder().setLanguageTag("en-US").build())); + Collator.getInstance(new Locale.Builder().setLanguageTag("en-US").build())); assertEqualCollation(expected, benchmark.getRunData().getAnalyzer(), "foobar"); // specify language + country + variant benchmark = execBenchmark(getCollatorConfig("no,NO,NY", "impl:jdk")); expected = new CollationKeyAnalyzer( - Collator.getInstance(Locale.Builder().setLanguageTag("no-NO-NY").build())); + Collator.getInstance(new Locale.Builder().setLanguageTag("no-NO-NY").build())); assertEqualCollation(expected, benchmark.getRunData().getAnalyzer(), "foobar"); } diff --git a/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/feeds/TestHtmlParser.java b/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/feeds/TestHtmlParser.java index d9c619d6488..c318a01e58a 100644 --- a/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/feeds/TestHtmlParser.java +++ b/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/feeds/TestHtmlParser.java @@ -96,7 +96,7 @@ public class TestHtmlParser extends LuceneTestCase { public void testTurkish() throws Exception { final Locale saved = Locale.getDefault(); try { - Locale.setDefault(Locale.Builder().setLanguageTag("tr-TR").build()); + Locale.setDefault(new Locale.Builder().setLanguageTag("tr-TR").build()); String text = "ııı" + "\"ş\"" diff --git a/lucene/luke/src/java/org/apache/lucene/luke/app/desktop/components/fragments/search/QueryParserPaneProvider.java b/lucene/luke/src/java/org/apache/lucene/luke/app/desktop/components/fragments/search/QueryParserPaneProvider.java index 0448611da4d..0c32b2a65eb 100644 --- a/lucene/luke/src/java/org/apache/lucene/luke/app/desktop/components/fragments/search/QueryParserPaneProvider.java +++ b/lucene/luke/src/java/org/apache/lucene/luke/app/desktop/components/fragments/search/QueryParserPaneProvider.java @@ -421,7 +421,7 @@ public final class QueryParserPaneProvider implements QueryParserTabOperator { .fuzzyMinSim(fuzzyMinSimFloat) .fuzzyPrefixLength(fuzzyPrefLenInt) .dateResolution(DateTools.Resolution.valueOf((String) dateResCB.getSelectedItem())) - .locale(Locale.Builder().setLanguageTag(locationTF.getText()).build()) + .locale(new Locale.Builder().setLanguageTag(locationTF.getText()).build()) .timeZone(TimeZone.getTimeZone(timezoneTF.getText())) .typeMap(typeMap) .build(); diff --git a/lucene/queryparser/src/test/org/apache/lucene/queryparser/flexible/messages/TestNLS.java b/lucene/queryparser/src/test/org/apache/lucene/queryparser/flexible/messages/TestNLS.java index af285a821b5..0065c45d3bd 100644 --- a/lucene/queryparser/src/test/org/apache/lucene/queryparser/flexible/messages/TestNLS.java +++ b/lucene/queryparser/src/test/org/apache/lucene/queryparser/flexible/messages/TestNLS.java @@ -68,7 +68,7 @@ public class TestNLS extends LuceneTestCase { } public void testNLSLoading_xx_XX() { - Locale locale = Locale.Builder().setLanguageTag("xx-XX").build(); + Locale locale = new Locale.Builder().setLanguageTag("xx-XX").build(); String message = NLS.getLocalizedMessage( MessagesTestBundle.Q0004E_INVALID_SYNTAX_ESCAPE_UNICODE_TRUNCATION, locale); From 073ad43229461fdce97b6c64488acc49ad36f36a Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Fri, 3 Nov 2023 12:47:50 -0400 Subject: [PATCH 09/23] run tests with java 21 --- .github/workflows/gradle-precommit.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/gradle-precommit.yml b/.github/workflows/gradle-precommit.yml index c6b5dfe38db..0e3c2d6c06b 100644 --- a/.github/workflows/gradle-precommit.yml +++ b/.github/workflows/gradle-precommit.yml @@ -59,7 +59,7 @@ jobs: # macos-latest: a tad slower than ubuntu and pretty much the same (?) so leaving out. os: [ubuntu-latest] # Test JVMs. - java: [ '17' ] + java: [ '21' ] env: GRADLE_ENTERPRISE_ACCESS_KEY: ${{ secrets.GE_ACCESS_TOKEN }} From 8bdc6a7aae2e04ecab78d03edf1a920d03378424 Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Fri, 3 Nov 2023 13:04:03 -0400 Subject: [PATCH 10/23] remove javaism completely --- .../benchmark/byTask/tasks/NewLocaleTask.java | 38 +++++-------------- .../benchmark/byTask/TestPerfTasksLogic.java | 14 ++----- 2 files changed, 13 insertions(+), 39 deletions(-) diff --git a/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/NewLocaleTask.java b/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/NewLocaleTask.java index bdd2224555c..7137bc1f6a5 100644 --- a/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/NewLocaleTask.java +++ b/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/NewLocaleTask.java @@ -17,26 +17,22 @@ package org.apache.lucene.benchmark.byTask.tasks; import java.util.Locale; -import java.util.StringTokenizer; import org.apache.lucene.benchmark.byTask.PerfRunData; /** * Set a {@link java.util.Locale} for use in benchmarking. * - *

Locales can be specified in the following ways: + *

Locales can be specified as BCP-47 language tag or as ROOT or empty string. * *

    *
  • de: Language "de" - *
  • en,US: Language "en", country "US" - *
  • no,NO,NY: Language "no", country "NO", variant "NY" + *
  • en-US: Language "en", country "US" *
  • ROOT: The root (language-agnostic) Locale *
  • <empty string>: Erase the Locale (null) *
*/ public class NewLocaleTask extends PerfTask { - private String language; - private String country; - private String variant; + private String tag; /** * Create a new {@link java.util.Locale} and set it in the getRunData() for use by all future @@ -46,31 +42,19 @@ public class NewLocaleTask extends PerfTask { super(runData); } - static Locale createLocale(String language, String country, String variant) { - if (language == null || language.length() == 0) return null; + static Locale createLocale(String tag) { + if (tag == null || tag.length() == 0) return null; - if (language.equalsIgnoreCase("ROOT")) { + if (tag.equalsIgnoreCase("ROOT")) { return Locale.ROOT; } - StringBuilder sb = new StringBuilder(); - sb.append(language); - if (country.length() > 0) { - sb.append('-'); - sb.append(country); - - if (variant.length() > 0) { - sb.append('-'); - sb.append(variant); - } - } - - return new Locale.Builder().setLanguageTag(sb.toString()).build(); + return new Locale.Builder().setLanguageTag(tag).build(); } @Override public int doLogic() throws Exception { - Locale locale = createLocale(language, country, variant); + Locale locale = createLocale(tag); getRunData().setLocale(locale); System.out.println( "Changed Locale to: " @@ -83,11 +67,7 @@ public class NewLocaleTask extends PerfTask { @Override public void setParams(String params) { super.setParams(params); - language = country = variant = ""; - StringTokenizer st = new StringTokenizer(params, ","); - if (st.hasMoreTokens()) language = st.nextToken(); - if (st.hasMoreTokens()) country = st.nextToken(); - if (st.hasMoreTokens()) variant = st.nextToken(); + tag = params; } @Override diff --git a/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/TestPerfTasksLogic.java b/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/TestPerfTasksLogic.java index 44885ec54b9..312e1c1fdf7 100644 --- a/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/TestPerfTasksLogic.java +++ b/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/TestPerfTasksLogic.java @@ -801,15 +801,9 @@ public class TestPerfTasksLogic extends BenchmarkTestCase { new Locale.Builder().setLanguageTag("de").build(), benchmark.getRunData().getLocale()); // specify language + country - benchmark = execBenchmark(getLocaleConfig("en,US")); + benchmark = execBenchmark(getLocaleConfig("en-US")); assertEquals( new Locale.Builder().setLanguageTag("en-US").build(), benchmark.getRunData().getLocale()); - - // specify language + country + variant - benchmark = execBenchmark(getLocaleConfig("no,NO,NY")); - assertEquals( - new Locale.Builder().setLanguageTag("no-NO-NY").build(), - benchmark.getRunData().getLocale()); } private String[] getLocaleConfig(String localeParam) { @@ -847,17 +841,17 @@ public class TestPerfTasksLogic extends BenchmarkTestCase { assertEqualCollation(expected, benchmark.getRunData().getAnalyzer(), "foobar"); // specify language + country - benchmark = execBenchmark(getCollatorConfig("en,US", "impl:jdk")); + benchmark = execBenchmark(getCollatorConfig("en-US", "impl:jdk")); expected = new CollationKeyAnalyzer( Collator.getInstance(new Locale.Builder().setLanguageTag("en-US").build())); assertEqualCollation(expected, benchmark.getRunData().getAnalyzer(), "foobar"); // specify language + country + variant - benchmark = execBenchmark(getCollatorConfig("no,NO,NY", "impl:jdk")); + benchmark = execBenchmark(getCollatorConfig("nn-NO", "impl:jdk")); expected = new CollationKeyAnalyzer( - Collator.getInstance(new Locale.Builder().setLanguageTag("no-NO-NY").build())); + Collator.getInstance(new Locale.Builder().setLanguageTag("nn-NO").build())); assertEqualCollation(expected, benchmark.getRunData().getAnalyzer(), "foobar"); } From fe0a483dc5c525838a310de90248b8ad2a7bf9a5 Mon Sep 17 00:00:00 2001 From: ChrisHegarty Date: Mon, 11 Dec 2023 14:18:57 +0000 Subject: [PATCH 11/23] remove ecj snapshot repo --- build.gradle | 6 ------ 1 file changed, 6 deletions(-) diff --git a/build.gradle b/build.gradle index 14beabb4250..309e903c5b2 100644 --- a/build.gradle +++ b/build.gradle @@ -101,12 +101,6 @@ dependencies { groovy "org.codehaus.groovy:groovy-all:3.0.12" } -repositories { - maven { - url "https://repo.eclipse.org/content/repositories/eclipse-snapshots/" - } -} - apply from: file('buildSrc/scriptDepVersions.gradle') // Include smaller chunks configuring dedicated build areas. From 4ef0c044d7e557a650c5b8a0cf6b3981dd3d7ae4 Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Mon, 5 Feb 2024 10:42:23 -0500 Subject: [PATCH 12/23] update README.md for java 21 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d8ff9234044..7a167e7455d 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ comprehensive documentation, visit: ### Basic steps: -1. Install OpenJDK 17 or 18. +1. Install OpenJDK 21. 2. Clone Lucene's git repository (or download the source distribution). 3. Run gradle launcher script (`gradlew`). From d75b869d2115b8f2eb18a1df4bc2b55f0552934a Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Fri, 9 Feb 2024 15:13:37 -0500 Subject: [PATCH 13/23] java 17 -> java 21 --- .../main/java/org/apache/lucene/gradle/WrapperDownloader.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/buildSrc/src/main/java/org/apache/lucene/gradle/WrapperDownloader.java b/buildSrc/src/main/java/org/apache/lucene/gradle/WrapperDownloader.java index 5123291bb83..d933a519a08 100644 --- a/buildSrc/src/main/java/org/apache/lucene/gradle/WrapperDownloader.java +++ b/buildSrc/src/main/java/org/apache/lucene/gradle/WrapperDownloader.java @@ -61,8 +61,8 @@ public class WrapperDownloader { public static void checkVersion() { int major = Runtime.getRuntime().version().feature(); - if (major < 17 || major > 21) { - throw new IllegalStateException("java version must be between 17 and 21, your version: " + major); + if (major != 21) { + throw new IllegalStateException("java version must be 21, your version: " + major); } } From a221b1f67798749195999999ae14ffc4092af6a8 Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Fri, 9 Feb 2024 15:14:20 -0500 Subject: [PATCH 14/23] java 17 -> java 21 --- buildSrc/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/buildSrc/build.gradle b/buildSrc/build.gradle index 9879caa8e18..db63485924d 100644 --- a/buildSrc/build.gradle +++ b/buildSrc/build.gradle @@ -21,7 +21,7 @@ repositories { ext { // Minimum Java version required to compile buildSrc. - minJavaVersion = JavaVersion.VERSION_17 + minJavaVersion = JavaVersion.VERSION_21 } From 784c331b6838642d364a31c5df07ef601e2f427e Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Fri, 9 Feb 2024 15:14:55 -0500 Subject: [PATCH 15/23] java 17 -> java 21 --- gradle/documentation/render-javadoc.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle/documentation/render-javadoc.gradle b/gradle/documentation/render-javadoc.gradle index 8e73fb1563c..f76a2c401c2 100644 --- a/gradle/documentation/render-javadoc.gradle +++ b/gradle/documentation/render-javadoc.gradle @@ -423,7 +423,7 @@ class RenderJavadocTask extends DefaultTask { opts << [ '-linkoffline', url, dir ] } - opts << [ '--release', 17 ] + opts << [ '--release', 21 ] opts << '-Xdoclint:all,-missing' // Increase Javadoc's heap. From 1f9545e830ca199f7c89d601554733fe3c0898d3 Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Fri, 9 Feb 2024 15:15:52 -0500 Subject: [PATCH 16/23] remove java < 21 --- gradle/template.gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle/template.gradle.properties b/gradle/template.gradle.properties index 9ac8c42e9dd..60486b86967 100644 --- a/gradle/template.gradle.properties +++ b/gradle/template.gradle.properties @@ -102,5 +102,5 @@ tests.jvms=@TEST_JVMS@ org.gradle.java.installations.auto-download=true # Set these to enable automatic JVM location discovery. -org.gradle.java.installations.fromEnv=JAVA17_HOME,JAVA19_HOME,JAVA20_HOME,JAVA21_HOME,JAVA22_HOME,RUNTIME_JAVA_HOME +org.gradle.java.installations.fromEnv=JAVA21_HOME,JAVA22_HOME,RUNTIME_JAVA_HOME #org.gradle.java.installations.paths=(custom paths) From fefde0f721afb7d20f0c936118a3b40699e24997 Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Fri, 9 Feb 2024 15:16:41 -0500 Subject: [PATCH 17/23] java 17 -> java 21 --- gradle/validation/ecj-lint/ecj.javadocs.prefs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/gradle/validation/ecj-lint/ecj.javadocs.prefs b/gradle/validation/ecj-lint/ecj.javadocs.prefs index 813aa7fe4cc..6da3899a27f 100644 --- a/gradle/validation/ecj-lint/ecj.javadocs.prefs +++ b/gradle/validation/ecj-lint/ecj.javadocs.prefs @@ -10,9 +10,9 @@ org.eclipse.jdt.core.compiler.annotation.nullable.secondary= org.eclipse.jdt.core.compiler.annotation.nullanalysis=disabled org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate -org.eclipse.jdt.core.compiler.codegen.targetPlatform=17 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=21 org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve -org.eclipse.jdt.core.compiler.compliance=17 +org.eclipse.jdt.core.compiler.compliance=21 org.eclipse.jdt.core.compiler.debug.lineNumber=generate org.eclipse.jdt.core.compiler.debug.localVariable=generate org.eclipse.jdt.core.compiler.debug.sourceFile=generate @@ -143,7 +143,7 @@ org.eclipse.jdt.core.compiler.problem.unusedTypeParameter=error org.eclipse.jdt.core.compiler.problem.unusedWarningToken=ignore org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=error org.eclipse.jdt.core.compiler.release=disabled -org.eclipse.jdt.core.compiler.source=17 +org.eclipse.jdt.core.compiler.source=21 org.eclipse.jdt.core.compiler.taskCaseSensitive=enabled org.eclipse.jdt.core.compiler.taskPriorities=HIGH -org.eclipse.jdt.core.compiler.taskTags=nocommit \ No newline at end of file +org.eclipse.jdt.core.compiler.taskTags=nocommit From 23ecac438a389adfce1a6166f57abd7df9dc0343 Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Fri, 9 Feb 2024 15:17:46 -0500 Subject: [PATCH 18/23] java 17 -> java 21 --- gradlew | 2 +- gradlew.bat | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/gradlew b/gradlew index c4770259bf7..8765922447e 100755 --- a/gradlew +++ b/gradlew @@ -160,7 +160,7 @@ GRADLE_WRAPPER_JAR="$APP_HOME/gradle/wrapper/gradle-wrapper.jar" "$JAVACMD" $JAVA_OPTS --source 11 "$APP_HOME/buildSrc/src/main/java/org/apache/lucene/gradle/WrapperDownloader.java" "$GRADLE_WRAPPER_JAR" WRAPPER_STATUS=$? if [ "$WRAPPER_STATUS" -eq 1 ]; then - echo "ERROR: Something went wrong. Make sure you're using Java version between 17 and 21." + echo "ERROR: Something went wrong. Make sure you're using Java version of exactly 21." exit $WRAPPER_STATUS elif [ "$WRAPPER_STATUS" -ne 0 ]; then exit $WRAPPER_STATUS diff --git a/gradlew.bat b/gradlew.bat index ca7ae1a1741..23a9b785a93 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -106,7 +106,7 @@ goto fail :failWithJvmMessage @rem https://github.com/apache/lucene/pull/819 -echo Error: Something went wrong. Make sure you're using Java version between 17 and 21. +echo Error: Something went wrong. Make sure you're using Java version of exactly 21. :fail rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of From ec04490bd2a81bd52eaefee4b1b6a2af0314238d Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Fri, 9 Feb 2024 15:18:30 -0500 Subject: [PATCH 19/23] java 17 -> java 21 --- lucene/SYSTEM_REQUIREMENTS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lucene/SYSTEM_REQUIREMENTS.md b/lucene/SYSTEM_REQUIREMENTS.md index b158d16b1c4..5a96b411fbc 100644 --- a/lucene/SYSTEM_REQUIREMENTS.md +++ b/lucene/SYSTEM_REQUIREMENTS.md @@ -17,7 +17,7 @@ # System Requirements -Apache Lucene runs on Java 17 or greater. +Apache Lucene runs on Java 21 or greater. It is also recommended to always use the latest update version of your Java VM, because bugs may affect Lucene. An overview of known JVM bugs From c7b05f56bdd5d9d89246843c70a6373f7da9bbb7 Mon Sep 17 00:00:00 2001 From: ChrisHegarty Date: Mon, 19 Feb 2024 11:45:18 +0000 Subject: [PATCH 20/23] post merge fix --- .github/actions/prepare-for-build/action.yml | 2 +- .github/workflows/run-checks-all.yml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/actions/prepare-for-build/action.yml b/.github/actions/prepare-for-build/action.yml index 92e751f60bb..1df2a44b634 100644 --- a/.github/actions/prepare-for-build/action.yml +++ b/.github/actions/prepare-for-build/action.yml @@ -6,7 +6,7 @@ name: Prepare Lucene build inputs: java-version: required: false - default: 17 + default: 21 description: "The default JDK version to set up." java-distribution: diff --git a/.github/workflows/run-checks-all.yml b/.github/workflows/run-checks-all.yml index 98248c9ad7d..3f899903dce 100644 --- a/.github/workflows/run-checks-all.yml +++ b/.github/workflows/run-checks-all.yml @@ -29,7 +29,7 @@ jobs: strategy: matrix: os: [ ubuntu-latest ] - java: [ '17' ] + java: [ '21' ] runs-on: ${{ matrix.os }} @@ -52,7 +52,7 @@ jobs: # windows-latest: fairly slow to build and results in odd errors (see LUCENE-10167) # macos-latest: a tad slower than ubuntu and pretty much the same (?) so leaving out. os: [ ubuntu-latest ] - java: [ '17' ] + java: [ '21' ] runs-on: ${{ matrix.os }} From e63df4d8796a3cb77e6a073a359dfaabcec4e1e4 Mon Sep 17 00:00:00 2001 From: ChrisHegarty Date: Fri, 23 Feb 2024 17:07:31 +0000 Subject: [PATCH 21/23] update changes.txt --- lucene/CHANGES.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt index b2e96bfbb06..8eff18dfaf8 100644 --- a/lucene/CHANGES.txt +++ b/lucene/CHANGES.txt @@ -153,9 +153,6 @@ Other * LUCENE-10376: Roll up the loop in VInt/VLong in DataInput. (Guo Feng) -* LUCENE-10283: The minimum required Java version was bumped from 11 to 17. - (Adrien Grand, Uwe Schindler, Dawid Weiss, Robert Muir) - * LUCENE-10253: The @BadApple annotation has been removed from the test framework. (Adrien Grand) @@ -178,6 +175,9 @@ Other * GITHUB#13001: Put Thread#sleep() on the list of forbidden APIs. (Shubham Chaudhary) +* GITHUB#12753: Bump minimum required Java version to 21 + (Chris Hegarty, Robert Muir, Uwe Schindler) + ======================== Lucene 9.11.0 ======================= API Changes From 3d7c88e695daf470b1ad446db47d853fca468280 Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Sat, 24 Feb 2024 15:08:11 -0500 Subject: [PATCH 22/23] fix release wizard --- dev-tools/scripts/releaseWizard.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dev-tools/scripts/releaseWizard.py b/dev-tools/scripts/releaseWizard.py index 2fe72a65f2c..562abf8f6e7 100755 --- a/dev-tools/scripts/releaseWizard.py +++ b/dev-tools/scripts/releaseWizard.py @@ -66,7 +66,7 @@ from consolemenu.items import FunctionItem, SubmenuItem, ExitItem from scriptutil import BranchType, Version, download, run # Lucene-to-Java version mapping -java_versions = {6: 8, 7: 8, 8: 8, 9: 11, 10: 17} +java_versions = {6: 8, 7: 8, 8: 8, 9: 11, 10: 21} editor = None # Edit this to add other global jinja2 variables or filters From 738d661b945d1ea2b5d8c9d3ba81d43cf1bbf720 Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Sat, 24 Feb 2024 15:11:24 -0500 Subject: [PATCH 23/23] fix smoketester --- dev-tools/scripts/smokeTestRelease.py | 30 +++++++++++++-------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/dev-tools/scripts/smokeTestRelease.py b/dev-tools/scripts/smokeTestRelease.py index 5b6ae716876..c62ce9e5451 100755 --- a/dev-tools/scripts/smokeTestRelease.py +++ b/dev-tools/scripts/smokeTestRelease.py @@ -144,10 +144,10 @@ def checkJARMetaData(desc, jarFile, gitRevision, version): 'Implementation-Vendor: The Apache Software Foundation', 'Specification-Title: Lucene Search Engine:', 'Implementation-Title: org.apache.lucene', - 'X-Compile-Source-JDK: 17', - 'X-Compile-Target-JDK: 17', + 'X-Compile-Source-JDK: 21', + 'X-Compile-Target-JDK: 21', 'Specification-Version: %s' % version, - 'X-Build-JDK: 17.', + 'X-Build-JDK: 21.', 'Extension-Name: org.apache.lucene'): if type(verify) is not tuple: verify = (verify,) @@ -611,13 +611,13 @@ def verifyUnpacked(java, artifact, unpackPath, gitRevision, version, testArgs): validateCmd = './gradlew --no-daemon check -p lucene/documentation' print(' run "%s"' % validateCmd) - java.run_java17(validateCmd, '%s/validate.log' % unpackPath) + java.run_java21(validateCmd, '%s/validate.log' % unpackPath) - print(" run tests w/ Java 17 and testArgs='%s'..." % testArgs) - java.run_java17('./gradlew --no-daemon test %s' % testArgs, '%s/test.log' % unpackPath) - print(" compile jars w/ Java 17") - java.run_java17('./gradlew --no-daemon jar -Dversion.release=%s' % version, '%s/compile.log' % unpackPath) - testDemo(java.run_java17, isSrc, version, '17') + print(" run tests w/ Java 21 and testArgs='%s'..." % testArgs) + java.run_java21('./gradlew --no-daemon test %s' % testArgs, '%s/test.log' % unpackPath) + print(" compile jars w/ Java 21") + java.run_java21('./gradlew --no-daemon jar -Dversion.release=%s' % version, '%s/compile.log' % unpackPath) + testDemo(java.run_java21, isSrc, version, '21') if java.run_java19: print(" run tests w/ Java 19 and testArgs='%s'..." % testArgs) @@ -633,7 +633,7 @@ def verifyUnpacked(java, artifact, unpackPath, gitRevision, version, testArgs): checkAllJARs(os.getcwd(), gitRevision, version) - testDemo(java.run_java17, isSrc, version, '17') + testDemo(java.run_java21, isSrc, version, '21') if java.run_java19: testDemo(java.run_java19, isSrc, version, '19') @@ -925,16 +925,16 @@ def make_java_config(parser, java19_home): def run_java(cmd, logfile): run('%s; %s' % (cmd_prefix, cmd), logfile) return run_java - java17_home = os.environ.get('JAVA_HOME') - if java17_home is None: + java21_home = os.environ.get('JAVA_HOME') + if java21_home is None: parser.error('JAVA_HOME must be set') - run_java17 = _make_runner(java17_home, '17') + run_java21 = _make_runner(java21_home, '21') run_java19 = None if java19_home is not None: run_java19 = _make_runner(java19_home, '19') - jc = namedtuple('JavaConfig', 'run_java17 java17_home run_java19 java19_home') - return jc(run_java17, java17_home, run_java19, java19_home) + jc = namedtuple('JavaConfig', 'run_java21 java21_home run_java19 java19_home') + return jc(run_java21, java21_home, run_java19, java19_home) version_re = re.compile(r'(\d+\.\d+\.\d+(-ALPHA|-BETA)?)') revision_re = re.compile(r'rev-([a-f\d]+)')