Skip to content

Apache Lucene open-source search software

build: enable more of javac 24's lints, fix some issues (#14907)

Robert Muirb47ba979f69f
diff --git a/build-tools/build-infra/src/main/groovy/lucene.regenerate.javacc.gradle b/build-tools/build-infra/src/main/groovy/lucene.regenerate.javacc.gradle
index 0b0700b0dd0..7ebdd6ad974 100644
--- a/build-tools/build-infra/src/main/groovy/lucene.regenerate.javacc.gradle
+++ b/build-tools/build-infra/src/main/groovy/lucene.regenerate.javacc.gradle
@@ -81,6 +81,13 @@ def commonCleanups = { FileTree generatedFiles ->
text = text.replace(
"public void setDebugStream(java.io.PrintStream ds) { debugStream = ds; }",
"// (setDebugStream omitted).")
+ // Remove dangling doc comments
+ text = text.replace(
+ "/** Debug output. */",
+ "// Debug output.")
+ text = text.replace(
+ "/** Set debug output. */",
+ "// Set debug output.")
return text
})
}
diff --git a/build-tools/build-infra/src/main/java/org/apache/lucene/gradle/plugins/java/JavacConfigurationPlugin.java b/build-tools/build-infra/src/main/java/org/apache/lucene/gradle/plugins/java/JavacConfigurationPlugin.java
index 72276d3b018..aecbd0081a8 100644
--- a/build-tools/build-infra/src/main/java/org/apache/lucene/gradle/plugins/java/JavacConfigurationPlugin.java
+++ b/build-tools/build-infra/src/main/java/org/apache/lucene/gradle/plugins/java/JavacConfigurationPlugin.java
@@ -68,6 +68,7 @@ public class JavacConfigurationPlugin extends LuceneGradlePlugin {
"-Xlint:auxiliaryclass",
"-Xlint:cast",
"-Xlint:classfile",
+ "-Xlint:dangling-doc-comments",
"-Xlint:-deprecation",
"-Xlint:dep-ann",
"-Xlint:divzero",
@@ -76,16 +77,18 @@ public class JavacConfigurationPlugin extends LuceneGradlePlugin {
"-Xlint:-exports",
"-Xlint:fallthrough",
"-Xlint:finally",
- // TODO: untested
+ "-Xlint:incubating",
+ // TODO: there are problems
+ "-Xlint:-lossy-conversions",
+ // TODO: there are problems
"-Xlint:-missing-explicit-ctor",
"-Xlint:module",
"-Xlint:opens",
"-Xlint:options",
+ "-Xlint:output-file-clash",
"-Xlint:overloads",
"-Xlint:overrides",
- // TODO: some tests seem to have bad classpaths?
- // this check seems to be a good sanity check for gradle?
- "-Xlint:-path",
+ "-Xlint:path",
"-Xlint:processing",
"-Xlint:rawtypes",
"-Xlint:removal",
@@ -96,10 +99,13 @@ public class JavacConfigurationPlugin extends LuceneGradlePlugin {
"-Xlint:strictfp",
"-Xlint:synchronization",
"-Xlint:text-blocks",
+ // TODO: there are problems
+ "-Xlint:-this-escape",
"-Xlint:try",
"-Xlint:unchecked",
"-Xlint:varargs",
"-Xlint:preview",
+ "-Xlint:restricted",
"-Xdoclint:all/protected",
"-Xdoclint:-missing",
"-Xdoclint:-accessibility"));
diff --git a/lucene/analysis/common/src/java/org/apache/lucene/analysis/compound/hyphenation/HyphenationTree.java b/lucene/analysis/common/src/java/org/apache/lucene/analysis/compound/hyphenation/HyphenationTree.java
index 49a12f365ef..85173427542 100644
--- a/lucene/analysis/common/src/java/org/apache/lucene/analysis/compound/hyphenation/HyphenationTree.java
+++ b/lucene/analysis/common/src/java/org/apache/lucene/analysis/compound/hyphenation/HyphenationTree.java
@@ -251,7 +251,7 @@ public class HyphenationTree extends TernaryTree implements PatternConsumer {
return hyphenate(w, 0, w.length, remainCharCount, pushCharCount);
}
- /**
+ /*
* w = "****nnllllllnnn*****", where n is a non-letter, l is a letter, all n may be absent, the
* first n is at offset, the first l is at offset + iIgnoreAtBeginning; word = ".llllll.'\0'***",
* where all l in w are copied into word. In the first part of the routine len = w.length, in the
diff --git a/lucene/analysis/common/src/java/org/apache/lucene/analysis/compound/hyphenation/TernaryTree.java b/lucene/analysis/common/src/java/org/apache/lucene/analysis/compound/hyphenation/TernaryTree.java
index 431556c6cf0..ee75d983a4d 100644
--- a/lucene/analysis/common/src/java/org/apache/lucene/analysis/compound/hyphenation/TernaryTree.java
+++ b/lucene/analysis/common/src/java/org/apache/lucene/analysis/compound/hyphenation/TernaryTree.java
@@ -54,7 +54,7 @@ import java.util.Enumeration;
*/
public class TernaryTree implements Cloneable {
- /**
+ /*
* We use 4 arrays to represent a node. I guess I should have created a proper node class, but
* somehow Knuth's pascal code made me forget we now have a portable language with virtual memory
* management and automatic garbage collection! And now is kind of late, furthermore, if it ain't
diff --git a/lucene/analysis/common/src/java/org/apache/lucene/analysis/de/GermanAnalyzer.java b/lucene/analysis/common/src/java/org/apache/lucene/analysis/de/GermanAnalyzer.java
index c6dcc8190b7..0f2b2c87eb7 100644
--- a/lucene/analysis/common/src/java/org/apache/lucene/analysis/de/GermanAnalyzer.java
+++ b/lucene/analysis/common/src/java/org/apache/lucene/analysis/de/GermanAnalyzer.java
@@ -86,8 +86,6 @@ public final class GermanAnalyzer extends StopwordAnalyzerBase {
}
}
- /** Contains the stopwords used with the {@link StopFilter}. */
-
/** Contains words that should be indexed but not stemmed. */
private final CharArraySet exclusionSet;
diff --git a/lucene/analysis/common/src/java/org/apache/lucene/analysis/en/KStemmer.java b/lucene/analysis/common/src/java/org/apache/lucene/analysis/en/KStemmer.java
index 1590c062efb..ba9287e1474 100644
--- a/lucene/analysis/common/src/java/org/apache/lucene/analysis/en/KStemmer.java
+++ b/lucene/analysis/common/src/java/org/apache/lucene/analysis/en/KStemmer.java
@@ -58,7 +58,7 @@ package org.apache.lucene.analysis.en;
import org.apache.lucene.analysis.CharArrayMap;
import org.apache.lucene.analysis.util.OpenStringBuilder;
-/**
+/*
* Title: Kstemmer
*
* <p>Description: This is a java version of Bob Krovetz' kstem stemmer
diff --git a/lucene/core/src/java/org/apache/lucene/store/PosixNativeAccess.java b/lucene/core/src/java/org/apache/lucene/store/PosixNativeAccess.java
index fea88e979e5..c84ecae7d2c 100644
--- a/lucene/core/src/java/org/apache/lucene/store/PosixNativeAccess.java
+++ b/lucene/core/src/java/org/apache/lucene/store/PosixNativeAccess.java
@@ -107,6 +107,7 @@ final class PosixNativeAccess extends NativeAccess {
return findFunction(linker, stdlib, "getpagesize", FunctionDescriptor.of(ValueLayout.JAVA_INT));
}
+ @SuppressWarnings("restricted") // unsafe functionality is used
private static MethodHandle findFunction(
Linker linker, SymbolLookup lookup, String name, FunctionDescriptor desc) {
final MemorySegment symbol =
diff --git a/lucene/memory/src/java/org/apache/lucene/index/memory/MemoryIndex.java b/lucene/memory/src/java/org/apache/lucene/index/memory/MemoryIndex.java
index 697623c51b5..b6b1db2637a 100644
--- a/lucene/memory/src/java/org/apache/lucene/index/memory/MemoryIndex.java
+++ b/lucene/memory/src/java/org/apache/lucene/index/memory/MemoryIndex.java
@@ -1368,9 +1368,7 @@ public class MemoryIndex {
}
}
- ///////////////////////////////////////////////////////////////////////////////
// Nested classes:
- ///////////////////////////////////////////////////////////////////////////////
private static class MemoryDocValuesIterator {
diff --git a/lucene/queryparser/src/generated/checksums/javaccParserClassic.json b/lucene/queryparser/src/generated/checksums/javaccParserClassic.json
index b91a38892f9..20195832496 100644
--- a/lucene/queryparser/src/generated/checksums/javaccParserClassic.json
+++ b/lucene/queryparser/src/generated/checksums/javaccParserClassic.json
@@ -3,7 +3,7 @@
"lucene/queryparser/src/java/org/apache/lucene/queryparser/classic/QueryParser.java": "2dfb7df4e711425be20c33a277a27d7e2972def1",
"lucene/queryparser/src/java/org/apache/lucene/queryparser/classic/QueryParser.jj": "82890f966a2456daf2b6100d3d79f77a861a2e03",
"lucene/queryparser/src/java/org/apache/lucene/queryparser/classic/QueryParserConstants.java": "e59a3fd38b66a3d56779c55955c1e014225a1f50",
- "lucene/queryparser/src/java/org/apache/lucene/queryparser/classic/QueryParserTokenManager.java": "dc99a1083bfa50e429d40e114fabe7dd5d434693",
+ "lucene/queryparser/src/java/org/apache/lucene/queryparser/classic/QueryParserTokenManager.java": "f5eb2a03a65caecff718b234d29390800c3e9be2",
"lucene/queryparser/src/java/org/apache/lucene/queryparser/classic/Token.java": "310665ba37d982327fcb55cc3523d629ef29ef54",
"lucene/queryparser/src/java/org/apache/lucene/queryparser/classic/TokenMgrError.java": "31afe7034729960514f50fdc3c9b33e0def44f1d"
}
diff --git a/lucene/queryparser/src/generated/checksums/javaccParserFlexible.json b/lucene/queryparser/src/generated/checksums/javaccParserFlexible.json
index 8a1336f301e..555e6bf0386 100644
--- a/lucene/queryparser/src/generated/checksums/javaccParserFlexible.json
+++ b/lucene/queryparser/src/generated/checksums/javaccParserFlexible.json
@@ -3,7 +3,7 @@
"lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/parser/StandardSyntaxParser.java": "55bd0228665fc67e6310558eb45c32ed1e20c32d",
"lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/parser/StandardSyntaxParser.jj": "cbcfc2d93dd684ab31e7824210cd167be210bce3",
"lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/parser/StandardSyntaxParserConstants.java": "d5e76f5f5522ae4b758d5c2f12e496fe182ae1f2",
- "lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/parser/StandardSyntaxParserTokenManager.java": "b00fca1e176bf95deb63fcb26f3eecd247b93a09",
+ "lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/parser/StandardSyntaxParserTokenManager.java": "49df9bdd3ca4a5f64aa5e3a9f1751e0bae637f03",
"lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/parser/Token.java": "d4603a7c273e0ef5e9c8890552779e40864185f4",
"lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/parser/TokenMgrError.java": "d474a0039c288e5e7dfa0a0e22e16e0e0fdaeaab"
}
diff --git a/lucene/queryparser/src/generated/checksums/javaccParserSurround.json b/lucene/queryparser/src/generated/checksums/javaccParserSurround.json
index 202af7d4c22..6ded352cfa1 100644
--- a/lucene/queryparser/src/generated/checksums/javaccParserSurround.json
+++ b/lucene/queryparser/src/generated/checksums/javaccParserSurround.json
@@ -3,7 +3,7 @@
"lucene/queryparser/src/java/org/apache/lucene/queryparser/surround/parser/QueryParser.java": "b6fc4a6567f497c60c26f752db7f229dd6504cd7",
"lucene/queryparser/src/java/org/apache/lucene/queryparser/surround/parser/QueryParser.jj": "b81635f8de654757290d99911adece916afe369a",
"lucene/queryparser/src/java/org/apache/lucene/queryparser/surround/parser/QueryParserConstants.java": "8feb77878890c27e874be457d839eba48192c40f",
- "lucene/queryparser/src/java/org/apache/lucene/queryparser/surround/parser/QueryParserTokenManager.java": "959523aec4e49f9665e39f16e1da335aab3632d1",
+ "lucene/queryparser/src/java/org/apache/lucene/queryparser/surround/parser/QueryParserTokenManager.java": "fcd1afca116eb6fa411d171e0b8a3c8729db1e0c",
"lucene/queryparser/src/java/org/apache/lucene/queryparser/surround/parser/Token.java": "a5eea2a3043e0aa2781f4a43b9ab9c5d59add80e",
"lucene/queryparser/src/java/org/apache/lucene/queryparser/surround/parser/TokenMgrError.java": "ee5fbd796ed8bd1c6e1a4b9e3d894f391da36236"
}
diff --git a/lucene/queryparser/src/java/org/apache/lucene/queryparser/classic/QueryParserTokenManager.java b/lucene/queryparser/src/java/org/apache/lucene/queryparser/classic/QueryParserTokenManager.java
index fb172fa6e36..3707bf06ec4 100644
--- a/lucene/queryparser/src/java/org/apache/lucene/queryparser/classic/QueryParserTokenManager.java
+++ b/lucene/queryparser/src/java/org/apache/lucene/queryparser/classic/QueryParserTokenManager.java
@@ -19,9 +19,9 @@ package org.apache.lucene.queryparser.classic;
@SuppressWarnings ("unused")
public class QueryParserTokenManager implements QueryParserConstants {
- /** Debug output. */
+ // Debug output.
// (debugStream omitted).
- /** Set debug output. */
+ // Set debug output.
// (setDebugStream omitted).
private final int jjStopStringLiteralDfa_2(int pos, long active0){
switch (pos)
diff --git a/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/parser/StandardSyntaxParserTokenManager.java b/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/parser/StandardSyntaxParserTokenManager.java
index 8c2fa93a2f9..7d3b735a4e3 100644
--- a/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/parser/StandardSyntaxParserTokenManager.java
+++ b/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/parser/StandardSyntaxParserTokenManager.java
@@ -73,9 +73,9 @@ package org.apache.lucene.queryparser.flexible.standard.parser;
@SuppressWarnings ("unused")
public class StandardSyntaxParserTokenManager implements StandardSyntaxParserConstants {
- /** Debug output. */
+ // Debug output.
// (debugStream omitted).
- /** Set debug output. */
+ // Set debug output.
// (setDebugStream omitted).
private final int jjStopStringLiteralDfa_2(int pos, long active0){
switch (pos)
diff --git a/lucene/queryparser/src/java/org/apache/lucene/queryparser/surround/parser/QueryParserTokenManager.java b/lucene/queryparser/src/java/org/apache/lucene/queryparser/surround/parser/QueryParserTokenManager.java
index 5b68a99be37..da81a994d56 100644
--- a/lucene/queryparser/src/java/org/apache/lucene/queryparser/surround/parser/QueryParserTokenManager.java
+++ b/lucene/queryparser/src/java/org/apache/lucene/queryparser/surround/parser/QueryParserTokenManager.java
@@ -22,9 +22,9 @@ package org.apache.lucene.queryparser.surround.parser;
@SuppressWarnings ("unused")
public class QueryParserTokenManager implements QueryParserConstants {
- /** Debug output. */
+ // Debug output.
// (debugStream omitted).
- /** Set debug output. */
+ // Set debug output.
// (setDebugStream omitted).
private final int jjStopStringLiteralDfa_1(int pos, long active0){
switch (pos)
diff --git a/lucene/sandbox/src/java/org/apache/lucene/sandbox/codecs/faiss/FaissKnnVectorsReader.java b/lucene/sandbox/src/java/org/apache/lucene/sandbox/codecs/faiss/FaissKnnVectorsReader.java
index 42a95145fbd..d54df42e813 100644
--- a/lucene/sandbox/src/java/org/apache/lucene/sandbox/codecs/faiss/FaissKnnVectorsReader.java
+++ b/lucene/sandbox/src/java/org/apache/lucene/sandbox/codecs/faiss/FaissKnnVectorsReader.java
@@ -153,6 +153,7 @@ final class FaissKnnVectorsReader extends KnnVectorsReader {
return new FieldMeta(fieldInfo, dataOffset, dataLength);
}
+ @SuppressWarnings("restricted") // TODO: encapsulate the unsafeness into the LibFaissC
private static IndexEntry loadField(IndexInput data, Arena arena, FieldMeta fieldMeta)
throws IOException {
int ioFlags = FAISS_IO_FLAG_MMAP | FAISS_IO_FLAG_READ_ONLY;
diff --git a/lucene/sandbox/src/java/org/apache/lucene/sandbox/codecs/faiss/FaissKnnVectorsWriter.java b/lucene/sandbox/src/java/org/apache/lucene/sandbox/codecs/faiss/FaissKnnVectorsWriter.java
index 0336e85e607..a81864a9c25 100644
--- a/lucene/sandbox/src/java/org/apache/lucene/sandbox/codecs/faiss/FaissKnnVectorsWriter.java
+++ b/lucene/sandbox/src/java/org/apache/lucene/sandbox/codecs/faiss/FaissKnnVectorsWriter.java
@@ -154,6 +154,7 @@ final class FaissKnnVectorsWriter extends KnnVectorsWriter {
}
}
+ @SuppressWarnings("restricted") // TODO: encapsulate the unsafeness into the LibFaissC
private void writeFloatField(
FieldInfo fieldInfo, FloatVectorValues floatVectorValues, IntToIntFunction oldToNewDocId)
throws IOException {
diff --git a/lucene/sandbox/src/java/org/apache/lucene/sandbox/codecs/faiss/LibFaissC.java b/lucene/sandbox/src/java/org/apache/lucene/sandbox/codecs/faiss/LibFaissC.java
index c7ad78ec672..d9a7baa8ef3 100644
--- a/lucene/sandbox/src/java/org/apache/lucene/sandbox/codecs/faiss/LibFaissC.java
+++ b/lucene/sandbox/src/java/org/apache/lucene/sandbox/codecs/faiss/LibFaissC.java
@@ -52,6 +52,7 @@ import org.apache.lucene.util.hnsw.IntToIntFunction;
*
* @lucene.experimental
*/
+@SuppressWarnings("restricted") // uses unsafe calls
final class LibFaissC {
// TODO: Use vectorized version where available
public static final String LIBRARY_NAME = "faiss_c";
diff --git a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/PlanetModel.java b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/PlanetModel.java
index 4095d8f9a5a..2a8a8d3dfe3 100644
--- a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/PlanetModel.java
+++ b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/PlanetModel.java
@@ -83,8 +83,6 @@ public class PlanetModel implements SerializableObject {
/** The inverse of scale */
public final double inverseScale;
- /** The mean radius of the planet model */
-
// We do NOT include radius, because all computations in geo3d are in radians, not meters.
// Compute north and south pole for planet model, since these are commonly used.
diff --git a/lucene/test-framework/src/java/org/apache/lucene/tests/util/LuceneTestCase.java b/lucene/test-framework/src/java/org/apache/lucene/tests/util/LuceneTestCase.java
index a019d5e9325..6feb39abb8c 100644
--- a/lucene/test-framework/src/java/org/apache/lucene/tests/util/LuceneTestCase.java
+++ b/lucene/test-framework/src/java/org/apache/lucene/tests/util/LuceneTestCase.java
@@ -774,22 +774,6 @@ public abstract class LuceneTestCase extends Assert {
return threadAndTestNameRule.testMethodName;
}
- /**
- * Some tests expect the directory to contain a single segment, and want to do tests on that
- * segment's reader. This is an utility method to help them.
- */
- /*
- public static SegmentReader getOnlySegmentReader(DirectoryReader reader) {
- List<LeafReaderContext> subReaders = reader.leaves();
- if (subReaders.size() != 1) {
- throw new IllegalArgumentException(reader + " has " + subReaders.size() + " segments instead of exactly one");
- }
- final LeafReader r = subReaders.get(0).reader();
- assertTrue("expected a SegmentReader but got " + r, r instanceof SegmentReader);
- return (SegmentReader) r;
- }
- */
-
/**
* Some tests expect the directory to contain a single segment, and want to do tests on that
* segment's reader. This is an utility method to help them.
diff --git a/lucene/test-framework/src/java/org/apache/lucene/tests/util/automaton/AutomatonTestUtil.java b/lucene/test-framework/src/java/org/apache/lucene/tests/util/automaton/AutomatonTestUtil.java
index 8109b847d19..41af10e41c7 100644
--- a/lucene/test-framework/src/java/org/apache/lucene/tests/util/automaton/AutomatonTestUtil.java
+++ b/lucene/test-framework/src/java/org/apache/lucene/tests/util/automaton/AutomatonTestUtil.java
@@ -296,7 +296,7 @@ public class AutomatonTestUtil extends Assert {
}
}
- /**
+ /*
* below are original, unoptimized implementations of DFA operations for testing. These are from
* brics automaton, full license (BSD) below:
*/