LUCENE-10364: Prepare and update errorprone plugin for Java 17 (#590)

This commit is contained in:
Uwe Schindler 2022-01-07 19:19:46 +01:00 committed by GitHub
parent d0ad9f5bfc
commit 42fe2d5620
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
27 changed files with 190 additions and 193 deletions

View File

@ -24,7 +24,7 @@ plugins {
id "org.owasp.dependencycheck" version "5.3.0"
id 'de.thetaphi.forbiddenapis' version '3.2' apply false
id "de.undercouch.download" version "4.1.1" apply false
id "net.ltgt.errorprone" version "1.2.1" apply false
id "net.ltgt.errorprone" version "2.0.2" apply false
id 'com.diffplug.spotless' version "5.14.3" apply false
}

View File

@ -88,3 +88,5 @@ if (jvmGradle != jvmCurrent) {
rootProject.ext.runtimeJavaExecutable = jvmCurrent.javaExecutable
rootProject.ext.runtimeJavaHome = jvmCurrent.javaHome
rootProject.ext.runtimeJavaVersion = jvmDetector.getMetadata(jvmCurrent.javaHome).languageVersion
rootProject.ext.usesAltJvm = (jvmGradle != jvmCurrent);

View File

@ -17,12 +17,12 @@
def skipReason
if (rootProject.runtimeJavaVersion > JavaVersion.VERSION_15) {
skipReason = "won't work with JDK ${rootProject.runtimeJavaVersion}"
if (rootProject.usesAltJvm && rootProject.runtimeJavaVersion > JavaVersion.VERSION_15) {
skipReason = "won't work with JDK ${rootProject.runtimeJavaVersion} if used as alternative java toolchain"
}
if (!Boolean.parseBoolean(propertyOrDefault("tests.nightly", "false"))) {
skipReason = "skipped on non-nightly runs"
skipReason = "skipped on non-nightly runs, pass -Dtests.nightly=true to run"
}
if (skipReason) {
@ -37,8 +37,10 @@ if (skipReason) {
allprojects { prj ->
plugins.withType(JavaPlugin) {
// LUCENE-9650: Errorprone on master/gradle does not work with JDK-16+
// this is a hack to keep the dependency (so that palantir's version check doesn't complain)
// LUCENE-9650: Errorprone on master/gradle does not work with JDK-16+ when running as plugin
// inside a forked Javac process. Javac running inside Gradle works, because we have
// additional module system opens in place.
// This is a hack to keep the dependency (so that palantir's version check doesn't complain)
// but don't include the plugin (which fails on JDK16+).
if (skipReason) {
tasks.withType(JavaCompile) { task -> task.dependsOn ":errorProneSkipped" }
@ -58,123 +60,110 @@ allprojects { prj ->
tasks.withType(JavaCompile) { task ->
options.errorprone.disableWarningsInGeneratedCode = true
options.errorprone.errorproneArgs = [
// test
'-Xep:ExtendingJUnitAssert:OFF',
'-Xep:UseCorrectAssertInTests:OFF',
'-Xep:DefaultPackage:OFF',
'-Xep:FloatingPointLiteralPrecision:OFF',
'-Xep:CatchFail:OFF',
'-Xep:TryFailThrowable:OFF',
'-Xep:MathAbsoluteRandom:OFF',
'-Xep:AssertionFailureIgnored:OFF',
'-Xep:JUnit4TestNotRun:OFF',
'-Xep:FallThrough:OFF',
'-Xep:CatchAndPrintStackTrace:OFF',
'-Xep:ToStringReturnsNull:OFF',
'-Xep:ArrayAsKeyOfSetOrMap:OFF',
'-Xep:StaticAssignmentInConstructor:OFF',
'-Xep:SelfAssignment:OFF',
'-Xep:InvalidPatternSyntax:OFF',
'-Xep:MissingFail:OFF',
'-Xep:LossyPrimitiveCompare:OFF',
'-Xep:ComparableType:OFF',
'-Xep:InfiniteRecursion:OFF',
'-Xep:MisusedDayOfYear:OFF',
'-Xep:FloatingPointAssertionWithinEpsilon:OFF',
'-Xep:InlineMeSuggester:OFF', // We don't use this annotation
'-Xep:ThrowNull:OFF',
'-Xep:StaticGuardedByInstance:OFF',
'-Xep:ArrayHashCode:OFF',
'-Xep:ArrayEquals:OFF',
'-Xep:IdentityBinaryExpression:OFF',
'-Xep:ComplexBooleanConstant:OFF',
'-Xep:ComplexBooleanConstant:OFF',
'-Xep:StreamResourceLeak:OFF',
'-Xep:UnnecessaryLambda:OFF',
'-Xep:ObjectToString:OFF',
'-Xep:URLEqualsHashCode:OFF',
'-Xep:DoubleBraceInitialization:OFF',
'-Xep:ShortCircuitBoolean:OFF',
'-Xep:InputStreamSlowMultibyteRead:OFF',
'-Xep:NonCanonicalType:OFF',
'-Xep:CollectionIncompatibleType:OFF',
'-Xep:TypeParameterShadowing:OFF',
'-Xep:ThreadJoinLoop:OFF',
'-Xep:MutableConstantField:OFF',
'-Xep:ReturnValueIgnored:OFF',
'-Xep:CollectionIncompatibleType:OFF',
'-Xep:SameNameButDifferent:OFF',
'-Xep:InvalidParam:OFF',
'-Xep:CompareToZero:OFF',
'-Xep:DoubleCheckedLocking:OFF',
'-Xep:BadShiftAmount:OFF',
'-Xep:CollectionUndefinedEquality:OFF',
'-Xep:UnescapedEntity:OFF',
'-Xep:BoxedPrimitiveEquality:OFF',
'-Xep:LogicalAssignment:OFF',
'-Xep:DoubleCheckedLocking:OFF',
'-Xep:AmbiguousMethodReference:OFF',
'-Xep:FormatString:OFF',
'-Xep:InstanceOfAndCastMatchWrongType:OFF',
'-Xep:ModifyCollectionInEnhancedForLoop:OFF',
'-Xep:JavaLangClash:OFF',
'-Xep:TypeParameterUnusedInFormals:OFF',
'-Xep:UnusedNestedClass:OFF',
'-Xep:OverrideThrowableToString:OFF',
'-Xep:FutureReturnValueIgnored:OFF',
'-Xep:BadInstanceof:OFF',
'-Xep:UnusedNestedClass:OFF',
'-Xep:OverrideThrowableToString:OFF',
'-Xep:EqualsIncompatibleType:OFF',
'-Xep:ByteBufferBackingArray:OFF',
'-Xep:ByteBufferBackingArray:OFF',
'-Xep:UnusedMethod:OFF',
'-Xep:ObjectsHashCodePrimitive:OFF',
'-Xep:ObjectsHashCodePrimitive:OFF',
'-Xep:UnnecessaryAnonymousClass:OFF',
'-Xep:BoxedPrimitiveConstructor:OFF',
'-Xep:ArgumentSelectionDefectChecker:OFF',
'-Xep:StringSplitter:OFF',
'-Xep:MixedMutabilityReturnType:OFF',
'-Xep:EqualsUnsafeCast:OFF',
'-Xep:OperatorPrecedence:OFF',
'-Xep:HidingField:OFF',
'-Xep:ThreadPriorityCheck:OFF',
'-Xep:InlineFormatString:OFF',
'-Xep:EqualsUnsafeCast:OFF',
'-Xep:UnsynchronizedOverridesSynchronized:OFF',
'-Xep:OperatorPrecedence:OFF',
'-Xep:ArrayToString:OFF',
'-Xep:ClassCanBeStatic:OFF',
'-Xep:InvalidInlineTag:OFF',
'-Xep:EmptyCatch:OFF',
'-Xep:UnnecessaryParentheses:OFF',
// test
'-Xep:AlmostJavadoc:OFF',
'-Xep:Finally:OFF',
'-Xep:ImmutableEnumChecker:OFF',
'-Xep:NonAtomicVolatileUpdate:OFF',
'-Xep:MutablePublicArray:OFF',
'-Xep:LockNotBeforeTry:OFF',
'-Xep:WaitNotInLoop:OFF',
'-Xep:UndefinedEquals:OFF',
'-Xep:JdkObsolete:OFF',
'-Xep:NarrowingCompoundAssignment:OFF',
'-Xep:InconsistentCapitalization:OFF',
'-Xep:IntLongMath:OFF',
'-Xep:SynchronizeOnNonFinalField:OFF',
'-Xep:ThreadLocalUsage:OFF',
'-Xep:ProtectedMembersInFinalClass:OFF',
'-Xep:AmbiguousMethodReference:OFF',
'-Xep:ArgumentSelectionDefectChecker:OFF',
'-Xep:ArrayAsKeyOfSetOrMap:OFF',
'-Xep:ArrayEquals:OFF',
'-Xep:ArrayHashCode:OFF',
'-Xep:ArrayToString:OFF',
'-Xep:AssertionFailureIgnored:OFF',
'-Xep:BadImport:OFF',
'-Xep:InconsistentHashCode:OFF',
'-Xep:MissingOverride:OFF',
'-Xep:BadInstanceof:OFF',
'-Xep:BadShiftAmount:OFF',
'-Xep:BoxedPrimitiveConstructor:OFF', // we have forbiddenapis for that
'-Xep:ByteBufferBackingArray:OFF',
'-Xep:CatchAndPrintStackTrace:OFF',
'-Xep:CatchFail:OFF',
'-Xep:CharacterGetNumericValue:OFF',
'-Xep:ClassCanBeStatic:OFF',
'-Xep:CollectionIncompatibleType:OFF',
'-Xep:CollectionUndefinedEquality:OFF',
'-Xep:ComparableType:OFF',
'-Xep:ComplexBooleanConstant:OFF',
'-Xep:DefaultPackage:OFF',
'-Xep:DoNotCallSuggester:OFF',
'-Xep:DoubleBraceInitialization:OFF',
'-Xep:DoubleCheckedLocking:OFF',
'-Xep:EmptyCatch:OFF',
'-Xep:EqualsGetClass:OFF',
'-Xep:PublicConstructorForAbstractClass:OFF',
'-Xep:EqualsIncompatibleType:OFF',
'-Xep:EqualsUnsafeCast:OFF',
'-Xep:EscapedEntity:OFF',
'-Xep:ModifiedButNotUsed:OFF',
'-Xep:ReferenceEquality:OFF',
'-Xep:ExtendingJUnitAssert:OFF',
'-Xep:FallThrough:OFF',
'-Xep:Finally:OFF',
'-Xep:FloatingPointLiteralPrecision:OFF',
'-Xep:FormatString:OFF',
'-Xep:FutureReturnValueIgnored:OFF',
'-Xep:HidingField:OFF',
'-Xep:IdentityBinaryExpression:OFF',
'-Xep:IdentityHashMapUsage:OFF',
'-Xep:ImmutableEnumChecker:OFF',
'-Xep:InconsistentCapitalization:OFF',
'-Xep:InconsistentHashCode:OFF',
'-Xep:InfiniteRecursion:OFF',
'-Xep:InlineFormatString:OFF',
'-Xep:InputStreamSlowMultibyteRead:OFF',
'-Xep:IntLongMath:OFF',
'-Xep:InvalidBlockTag:OFF',
'-Xep:InvalidInlineTag:OFF',
'-Xep:InvalidParam:OFF',
'-Xep:InvalidPatternSyntax:OFF',
'-Xep:JUnit4TestNotRun:OFF',
'-Xep:JavaLangClash:OFF',
'-Xep:JavaUtilDate:OFF',
'-Xep:JdkObsolete:OFF',
'-Xep:LockNotBeforeTry:OFF',
'-Xep:LogicalAssignment:OFF',
'-Xep:MathAbsoluteRandom:OFF',
'-Xep:MissingFail:OFF',
'-Xep:MissingOverride:OFF',
'-Xep:MissingSummary:OFF',
'-Xep:UnusedVariable:OFF'
'-Xep:MisusedDayOfYear:OFF',
'-Xep:MixedMutabilityReturnType:OFF',
'-Xep:ModifiedButNotUsed:OFF',
'-Xep:MutableConstantField:OFF',
'-Xep:MutablePublicArray:OFF',
'-Xep:NarrowingCompoundAssignment:OFF',
'-Xep:NonAtomicVolatileUpdate:OFF',
'-Xep:NonCanonicalType:OFF',
'-Xep:ObjectToString:OFF',
'-Xep:ObjectsHashCodePrimitive:OFF',
'-Xep:OperatorPrecedence:OFF',
'-Xep:ProtectedMembersInFinalClass:OFF',
'-Xep:PublicConstructorForAbstractClass:OFF',
'-Xep:ReferenceEquality:OFF',
'-Xep:ReturnValueIgnored:OFF',
'-Xep:SameNameButDifferent:OFF',
'-Xep:SelfAssignment:OFF',
'-Xep:ShortCircuitBoolean:OFF',
'-Xep:StaticAssignmentInConstructor:OFF',
'-Xep:StaticGuardedByInstance:OFF',
'-Xep:StreamResourceLeak:OFF',
'-Xep:StringSplitter:OFF',
'-Xep:SynchronizeOnNonFinalField:OFF',
'-Xep:ThreadJoinLoop:OFF',
'-Xep:ThreadLocalUsage:OFF',
'-Xep:ThreadPriorityCheck:OFF',
'-Xep:ThrowNull:OFF',
'-Xep:ToStringReturnsNull:OFF',
'-Xep:TryFailThrowable:OFF',
'-Xep:TypeParameterShadowing:OFF',
'-Xep:TypeParameterUnusedInFormals:OFF',
'-Xep:UndefinedEquals:OFF',
'-Xep:UnescapedEntity:OFF',
'-Xep:UnicodeEscape:OFF',
'-Xep:UnnecessaryLambda:OFF',
'-Xep:UnnecessaryParentheses:OFF',
'-Xep:UnsynchronizedOverridesSynchronized:OFF',
'-Xep:UnusedMethod:OFF',
'-Xep:UnusedVariable:OFF',
'-Xep:UseCorrectAssertInTests:OFF',
'-Xep:WaitNotInLoop:OFF',
]
}
}

View File

@ -333,7 +333,7 @@ public class MinHashFilter extends TokenFilter {
public boolean add(final E toAdd) {
if (capacity <= size()) {
final E lastElm = last();
if (toAdd.compareTo(lastElm) > -1) {
if (toAdd.compareTo(lastElm) >= 0) {
return false;
} else {
pollLast();

View File

@ -171,6 +171,8 @@ public class GenerateJflexTLDMacros {
* care about TLDs that are prefixes and are exactly one character shorter than another TLD. See
* LUCENE-8278 and LUCENE-5391.
*/
@SuppressWarnings(
"ModifyCollectionInEnhancedForLoop") // it looks like it works because it is a sorted map!
private void partitionTLDprefixesBySuffixLength() {
TLDsBySuffixLength.add(new TreeSet<>()); // initialize set for zero-suffix TLDs
for (SortedMap.Entry<String, Boolean> entry : processedTLDsLongestFirst.entrySet()) {

View File

@ -186,7 +186,7 @@ public abstract class ContentItemsSource implements Closeable {
sb.append("total bytes of ")
.append(itemsName)
.append(": ")
.append(Format.format(0, nub, col))
.append(Format.format(0, (double) nub, col))
.append(newline);
lastPrintedNumUniqueBytes = nub;
}
@ -200,7 +200,7 @@ public abstract class ContentItemsSource implements Closeable {
sb.append("total bytes added for ")
.append(itemsName)
.append(" since last inputs reset: ")
.append(Format.format(0, getBytesCount(), col))
.append(Format.format(0, (double) getBytesCount(), col))
.append(newline);
}
if (print) {

View File

@ -197,10 +197,10 @@ public class FuzzyQuery extends MultiTermQuery {
if (!super.equals(obj)) return false;
if (getClass() != obj.getClass()) return false;
FuzzyQuery other = (FuzzyQuery) obj;
return Objects.equals(maxEdits, other.maxEdits)
&& Objects.equals(prefixLength, other.prefixLength)
&& Objects.equals(maxExpansions, other.maxExpansions)
&& Objects.equals(transpositions, other.transpositions)
return maxEdits == other.maxEdits
&& prefixLength == other.prefixLength
&& maxExpansions == other.maxExpansions
&& transpositions == other.transpositions
&& Objects.equals(term, other.term);
}

View File

@ -498,6 +498,7 @@ public final class IOUtils {
* The first exception thrown by the consumer is re-thrown and subsequent exceptions are
* suppressed.
*/
@SuppressWarnings("StreamToIterable")
public static <T> void applyToAll(Collection<T> collection, IOConsumer<T> consumer)
throws IOException {
IOUtils.close(

View File

@ -529,7 +529,7 @@ public class TestLRUQueryCache extends LuceneTestCase {
final long actualRamBytesUsed = RamUsageTester.ramUsed(queryCache, acc);
final long expectedRamBytesUsed = queryCache.ramBytesUsed();
// error < 30%
assertEquals(actualRamBytesUsed, expectedRamBytesUsed, 30 * actualRamBytesUsed / 100);
assertEquals(actualRamBytesUsed, expectedRamBytesUsed, 30.d * actualRamBytesUsed / 100.d);
reader.close();
w.close();

View File

@ -23,6 +23,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.Random;
import java.util.concurrent.CountDownLatch;
import org.apache.lucene.document.Document;
@ -148,7 +149,7 @@ public class TestLiveFieldValues extends LuceneTestCase {
if (allIDs.size() > 0) {
String randomID = allIDs.get(threadRandom.nextInt(allIDs.size()));
Integer expected = values.get(randomID);
if (expected == missing) {
if (Objects.equals(expected, missing)) {
expected = null;
}
assertEquals("id=" + randomID, expected, rt.get(randomID));

View File

@ -187,7 +187,7 @@ public class TestTermInSetQuery extends LuceneTestCase {
final long actualRamBytesUsed = RamUsageTester.ramUsed(query);
final long expectedRamBytesUsed = query.ramBytesUsed();
// error margin within 5%
assertEquals(expectedRamBytesUsed, actualRamBytesUsed, actualRamBytesUsed / 20);
assertEquals(expectedRamBytesUsed, actualRamBytesUsed, actualRamBytesUsed / 20.d);
}
private static class TermsCountingDirectoryReaderWrapper extends FilterDirectoryReader {

View File

@ -120,7 +120,7 @@ public class TestBooleanSimilarity extends BaseSimilarityTestCase {
100,
maxTermFrequency,
uniqueTermCount);
assertEquals(sim2.computeNorm(state), sim1.computeNorm(state), 0f);
assertEquals(sim2.computeNorm(state), sim1.computeNorm(state));
}
}

View File

@ -190,7 +190,7 @@ public class TestClassicSimilarity extends BaseSimilarityTestCase {
100,
maxTermFrequency,
uniqueTermCount);
assertEquals(sim2.computeNorm(state), sim1.computeNorm(state), 0f);
assertEquals(sim2.computeNorm(state), sim1.computeNorm(state));
}
}

View File

@ -26,6 +26,7 @@ import org.apache.lucene.tests.util.TestUtil;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
@SuppressWarnings("BoxedPrimitiveEquality")
public class TestPriorityQueue extends LuceneTestCase {
private static class IntegerQueue extends PriorityQueue<Integer> {

View File

@ -1027,7 +1027,7 @@ public class TestAutomaton extends LuceneTestCase {
System.out.println(" prefixes=" + prefixes);
}
for (int prefix : prefixes) {
for (int prefix : prefixes.stream().mapToInt(Integer::intValue).toArray()) {
// prefix is a leading ascii byte; we retain <prefix>* in a
Automaton a2 = new Automaton();
int init = a2.createState();

View File

@ -143,7 +143,7 @@ public class TestRegExp extends LuceneTestCase {
break;
case 6:
// replace all chars with .
result.append(replacementPart.replaceAll(".", "."));
result.append(".".repeat(replacementPart.length()));
break;
case 7:
// OR with uppercase chars eg [aA] (many of these sorts of expression in the wild..

View File

@ -703,7 +703,7 @@ public class TestPackedInts extends LuceneTestCase {
}
// test ramBytesUsed
assertEquals(RamUsageTester.ramUsed(writer), writer.ramBytesUsed(), 8);
assertEquals(RamUsageTester.ramUsed(writer), writer.ramBytesUsed(), 8.d);
// test copy
PagedGrowableWriter copy =

View File

@ -93,7 +93,7 @@ public class TestParentChildrenBlockJoinQuery extends LuceneTestCase {
if (expectedChildDocs > 0) {
for (int i = 0; i < topDocs.scoreDocs.length; i++) {
ScoreDoc childScoreDoc = topDocs.scoreDocs[i];
assertEquals(expectedChildDocs - i, childScoreDoc.score, 0);
assertEquals((float) expectedChildDocs - i, childScoreDoc.score, 0.f);
}
}
}

View File

@ -102,7 +102,7 @@ public final class LogsPanelProvider {
String logContent =
clonedCopy.stream()
.filter(record -> record.getLevel().intValue() >= level.intValue())
.map(formatter::apply)
.map(formatter)
.collect(Collectors.joining("\n"));
logTextArea.setText(logContent);

View File

@ -116,8 +116,8 @@ public class FunctionRangeQuery extends Query {
}
private boolean equalsTo(FunctionRangeQuery other) {
return Objects.equals(includeLower, other.includeLower)
&& Objects.equals(includeUpper, other.includeUpper)
return includeLower == other.includeLower
&& includeUpper == other.includeUpper
&& Objects.equals(valueSource, other.valueSource)
&& Objects.equals(lowerVal, other.lowerVal)
&& Objects.equals(upperVal, other.upperVal);

View File

@ -109,7 +109,7 @@ class RepeatingIntervalsSource extends IntervalsSource {
public boolean equals(Object other) {
if (other instanceof RepeatingIntervalsSource == false) return false;
RepeatingIntervalsSource o = (RepeatingIntervalsSource) other;
return Objects.equals(this.in, o.in) && Objects.equals(this.childCount, o.childCount);
return Objects.equals(this.in, o.in) && this.childCount == o.childCount;
}
@Override

View File

@ -23,6 +23,7 @@ import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CountDownLatch;
@ -824,7 +825,7 @@ public class TestIDVersionPostingsFormat extends LuceneTestCase {
}
boolean doIndex;
if (currentVersion == missingValue) {
if (Objects.equals(currentVersion, missingValue)) {
if (VERBOSE) {
System.out.println(
Thread.currentThread().getName() + ": id not in RT cache");

View File

@ -217,7 +217,7 @@ public final class NRTSuggester implements Accountable {
collector.seenSurfaceForms.add(key);
}
try {
float score = scorer.score(decode(path.output.output1), path.boost);
float score = scorer.score((float) decode(path.output.output1), path.boost);
collector.collect(docID, spare.toCharsRef(), path.context, score);
return true;
} catch (IOException e) {
@ -275,8 +275,8 @@ public final class NRTSuggester implements Accountable {
Util.FSTPath<Pair<Long, BytesRef>> first, Util.FSTPath<Pair<Long, BytesRef>> second) {
int cmp =
Float.compare(
scorer.score(decode(second.output.output1), second.boost),
scorer.score(decode(first.output.output1), first.boost));
scorer.score((float) decode(second.output.output1), second.boost),
scorer.score((float) decode(first.output.output1), first.boost));
return (cmp != 0) ? cmp : first.input.get().compareTo(second.input.get());
}
}

View File

@ -82,32 +82,32 @@ public class TestAnalyzingSuggester extends LuceneTestCase {
suggester.lookup(TestUtil.stringToCharSequence("f", random()), false, 2);
assertEquals(1, results.size());
assertEquals("foo", results.get(0).key.toString());
assertEquals(50, results.get(0).value, 0.01F);
assertEquals(50, results.get(0).value);
// top N of 1 for 'bar': we return this even though
// barbar is higher because exactFirst is enabled:
results = suggester.lookup(TestUtil.stringToCharSequence("bar", random()), false, 1);
assertEquals(1, results.size());
assertEquals("bar", results.get(0).key.toString());
assertEquals(10, results.get(0).value, 0.01F);
assertEquals(10, results.get(0).value);
// top N Of 2 for 'b'
results = suggester.lookup(TestUtil.stringToCharSequence("b", random()), false, 2);
assertEquals(2, results.size());
assertEquals("barbar", results.get(0).key.toString());
assertEquals(12, results.get(0).value, 0.01F);
assertEquals(12, results.get(0).value);
assertEquals("bar", results.get(1).key.toString());
assertEquals(10, results.get(1).value, 0.01F);
assertEquals(10, results.get(1).value);
// top N of 3 for 'ba'
results = suggester.lookup(TestUtil.stringToCharSequence("ba", random()), false, 3);
assertEquals(3, results.size());
assertEquals("barbar", results.get(0).key.toString());
assertEquals(12, results.get(0).value, 0.01F);
assertEquals(12, results.get(0).value);
assertEquals("bar", results.get(1).key.toString());
assertEquals(10, results.get(1).value, 0.01F);
assertEquals(10, results.get(1).value);
assertEquals("barbara", results.get(2).key.toString());
assertEquals(6, results.get(2).value, 0.01F);
assertEquals(6, results.get(2).value);
IOUtils.close(analyzer, tempDir);
}
@ -132,7 +132,7 @@ public class TestAnalyzingSuggester extends LuceneTestCase {
suggester.lookup(TestUtil.stringToCharSequence("f", random()), false, 2);
assertEquals(1, results.size());
assertEquals("foo", results.get(0).key.toString());
assertEquals(50, results.get(0).value, 0.01F);
assertEquals(50, results.get(0).value);
assertEquals(new BytesRef("hello"), results.get(0).payload);
// top N of 1 for 'bar': we return this even though
@ -140,30 +140,30 @@ public class TestAnalyzingSuggester extends LuceneTestCase {
results = suggester.lookup(TestUtil.stringToCharSequence("bar", random()), false, 1);
assertEquals(1, results.size());
assertEquals("bar", results.get(0).key.toString());
assertEquals(10, results.get(0).value, 0.01F);
assertEquals(10, results.get(0).value);
assertEquals(new BytesRef("goodbye"), results.get(0).payload);
// top N Of 2 for 'b'
results = suggester.lookup(TestUtil.stringToCharSequence("b", random()), false, 2);
assertEquals(2, results.size());
assertEquals("barbar", results.get(0).key.toString());
assertEquals(12, results.get(0).value, 0.01F);
assertEquals(12, results.get(0).value);
assertEquals(new BytesRef("thank you"), results.get(0).payload);
assertEquals("bar", results.get(1).key.toString());
assertEquals(10, results.get(1).value, 0.01F);
assertEquals(10, results.get(1).value);
assertEquals(new BytesRef("goodbye"), results.get(1).payload);
// top N of 3 for 'ba'
results = suggester.lookup(TestUtil.stringToCharSequence("ba", random()), false, 3);
assertEquals(3, results.size());
assertEquals("barbar", results.get(0).key.toString());
assertEquals(12, results.get(0).value, 0.01F);
assertEquals(12, results.get(0).value);
assertEquals(new BytesRef("thank you"), results.get(0).payload);
assertEquals("bar", results.get(1).key.toString());
assertEquals(10, results.get(1).value, 0.01F);
assertEquals(10, results.get(1).value);
assertEquals(new BytesRef("goodbye"), results.get(1).payload);
assertEquals("barbara", results.get(2).key.toString());
assertEquals(6, results.get(2).value, 0.01F);
assertEquals(6, results.get(2).value);
assertEquals(new BytesRef("for all the fish"), results.get(2).payload);
}
IOUtils.close(analyzer, tempDir);
@ -259,26 +259,26 @@ public class TestAnalyzingSuggester extends LuceneTestCase {
results = suggester.lookup(TestUtil.stringToCharSequence(input, random()), false, 1);
assertEquals(1, results.size());
assertEquals(input, results.get(0).key.toString());
assertEquals(50, results.get(0).value, 0.01F);
assertEquals(50, results.get(0).value);
// prefix of input stopping part way through christmas
results =
suggester.lookup(TestUtil.stringToCharSequence("the ghost of chris", random()), false, 1);
assertEquals(1, results.size());
assertEquals(input, results.get(0).key.toString());
assertEquals(50, results.get(0).value, 0.01F);
assertEquals(50, results.get(0).value);
// omit the 'the' since it's a stopword, it's suggested anyway
results = suggester.lookup(TestUtil.stringToCharSequence("ghost of chris", random()), false, 1);
assertEquals(1, results.size());
assertEquals(input, results.get(0).key.toString());
assertEquals(50, results.get(0).value, 0.01F);
assertEquals(50, results.get(0).value);
// omit the 'the' and 'of' since they are stopwords, it's suggested anyway
results = suggester.lookup(TestUtil.stringToCharSequence("ghost chris", random()), false, 1);
assertEquals(1, results.size());
assertEquals(input, results.get(0).key.toString());
assertEquals(50, results.get(0).value, 0.01F);
assertEquals(50, results.get(0).value);
// trailing stopword "the"
results =
@ -286,7 +286,7 @@ public class TestAnalyzingSuggester extends LuceneTestCase {
TestUtil.stringToCharSequence("ghost christmas past the", random()), false, 1);
assertEquals(1, results.size());
assertEquals(input, results.get(0).key.toString());
assertEquals(50, results.get(0).value, 0.01F);
assertEquals(50, results.get(0).value);
IOUtils.close(standard, tempDir);
}
@ -911,7 +911,7 @@ public class TestAnalyzingSuggester extends LuceneTestCase {
new Comparator<TermFreq2>() {
@Override
public int compare(TermFreq2 left, TermFreq2 right) {
int cmp = Float.compare(right.weight, left.weight);
int cmp = Long.compare(right.weight, left.weight);
if (cmp == 0) {
return left.analyzedForm.compareTo(right.analyzedForm);
} else {
@ -942,7 +942,7 @@ public class TestAnalyzingSuggester extends LuceneTestCase {
for (int hit = 0; hit < r.size(); hit++) {
// System.out.println(" check hit " + hit);
assertEquals(matches.get(hit).surfaceForm.toString(), r.get(hit).key.toString());
assertEquals(matches.get(hit).weight, r.get(hit).value, 0f);
assertEquals(matches.get(hit).weight, r.get(hit).value);
if (doPayloads) {
assertEquals(matches.get(hit).payload, r.get(hit).payload);
}

View File

@ -84,7 +84,7 @@ public class TestFuzzySuggester extends LuceneTestCase {
suggester.lookup(TestUtil.stringToCharSequence(addRandomEdit, random()), false, 2);
assertEquals(addRandomEdit, 1, results.size());
assertEquals("foo bar boo far", results.get(0).key.toString());
assertEquals(12, results.get(0).value, 0.01F);
assertEquals(12, results.get(0).value);
}
IOUtils.close(analyzer, tempDir);
}
@ -121,7 +121,7 @@ public class TestFuzzySuggester extends LuceneTestCase {
suggester.lookup(TestUtil.stringToCharSequence(addRandomEdit, random()), false, 2);
assertEquals(addRandomEdit, 1, results.size());
assertEquals("фуу бар буу фар", results.get(0).key.toString());
assertEquals(12, results.get(0).value, 0.01F);
assertEquals(12, results.get(0).value);
}
IOUtils.close(analyzer, tempDir);
}
@ -145,62 +145,62 @@ public class TestFuzzySuggester extends LuceneTestCase {
suggester.lookup(TestUtil.stringToCharSequence("bariar", random()), false, 2);
assertEquals(2, results.size());
assertEquals("barbar", results.get(0).key.toString());
assertEquals(12, results.get(0).value, 0.01F);
assertEquals(12, results.get(0).value);
results = suggester.lookup(TestUtil.stringToCharSequence("barbr", random()), false, 2);
assertEquals(2, results.size());
assertEquals("barbar", results.get(0).key.toString());
assertEquals(12, results.get(0).value, 0.01F);
assertEquals(12, results.get(0).value);
results = suggester.lookup(TestUtil.stringToCharSequence("barbara", random()), false, 2);
assertEquals(2, results.size());
assertEquals("barbara", results.get(0).key.toString());
assertEquals(6, results.get(0).value, 0.01F);
assertEquals(6, results.get(0).value);
results = suggester.lookup(TestUtil.stringToCharSequence("barbar", random()), false, 2);
assertEquals(2, results.size());
assertEquals("barbar", results.get(0).key.toString());
assertEquals(12, results.get(0).value, 0.01F);
assertEquals(12, results.get(0).value);
assertEquals("barbara", results.get(1).key.toString());
assertEquals(6, results.get(1).value, 0.01F);
assertEquals(6, results.get(1).value);
results = suggester.lookup(TestUtil.stringToCharSequence("barbaa", random()), false, 2);
assertEquals(2, results.size());
assertEquals("barbar", results.get(0).key.toString());
assertEquals(12, results.get(0).value, 0.01F);
assertEquals(12, results.get(0).value);
assertEquals("barbara", results.get(1).key.toString());
assertEquals(6, results.get(1).value, 0.01F);
assertEquals(6, results.get(1).value);
// top N of 2, but only foo is available
results = suggester.lookup(TestUtil.stringToCharSequence("f", random()), false, 2);
assertEquals(1, results.size());
assertEquals("foo", results.get(0).key.toString());
assertEquals(50, results.get(0).value, 0.01F);
assertEquals(50, results.get(0).value);
// top N of 1 for 'bar': we return this even though
// barbar is higher because exactFirst is enabled:
results = suggester.lookup(TestUtil.stringToCharSequence("bar", random()), false, 1);
assertEquals(1, results.size());
assertEquals("bar", results.get(0).key.toString());
assertEquals(10, results.get(0).value, 0.01F);
assertEquals(10, results.get(0).value);
// top N Of 2 for 'b'
results = suggester.lookup(TestUtil.stringToCharSequence("b", random()), false, 2);
assertEquals(2, results.size());
assertEquals("barbar", results.get(0).key.toString());
assertEquals(12, results.get(0).value, 0.01F);
assertEquals(12, results.get(0).value);
assertEquals("bar", results.get(1).key.toString());
assertEquals(10, results.get(1).value, 0.01F);
assertEquals(10, results.get(1).value);
// top N of 3 for 'ba'
results = suggester.lookup(TestUtil.stringToCharSequence("ba", random()), false, 3);
assertEquals(3, results.size());
assertEquals("barbar", results.get(0).key.toString());
assertEquals(12, results.get(0).value, 0.01F);
assertEquals(12, results.get(0).value);
assertEquals("bar", results.get(1).key.toString());
assertEquals(10, results.get(1).value, 0.01F);
assertEquals(10, results.get(1).value);
assertEquals("barbara", results.get(2).key.toString());
assertEquals(6, results.get(2).value, 0.01F);
assertEquals(6, results.get(2).value);
IOUtils.close(analyzer, tempDir);
}
@ -236,19 +236,19 @@ public class TestFuzzySuggester extends LuceneTestCase {
suggester.lookup(TestUtil.stringToCharSequence("the ghost of chris", random()), false, 1);
assertEquals(1, results.size());
assertEquals("the ghost of christmas past", results.get(0).key.toString());
assertEquals(50, results.get(0).value, 0.01F);
assertEquals(50, results.get(0).value);
// omit the 'the' since it's a stopword, it's suggested anyway
results = suggester.lookup(TestUtil.stringToCharSequence("ghost of chris", random()), false, 1);
assertEquals(1, results.size());
assertEquals("the ghost of christmas past", results.get(0).key.toString());
assertEquals(50, results.get(0).value, 0.01F);
assertEquals(50, results.get(0).value);
// omit the 'the' and 'of' since they are stopwords, it's suggested anyway
results = suggester.lookup(TestUtil.stringToCharSequence("ghost chris", random()), false, 1);
assertEquals(1, results.size());
assertEquals("the ghost of christmas past", results.get(0).key.toString());
assertEquals(50, results.get(0).value, 0.01F);
assertEquals(50, results.get(0).value);
IOUtils.close(standard, tempDir);
}
@ -845,7 +845,7 @@ public class TestFuzzySuggester extends LuceneTestCase {
new Comparator<LookupResult>() {
@Override
public int compare(LookupResult left, LookupResult right) {
int cmp = Float.compare(right.value, left.value);
int cmp = Long.compare(right.value, left.value);
if (cmp == 0) {
return left.compareTo(right);
} else {
@ -876,7 +876,7 @@ public class TestFuzzySuggester extends LuceneTestCase {
// System.out.println(" check hit " + hit);
assertEquals(
prefix + " " + topN, matches.get(hit).key.toString(), r.get(hit).key.toString());
assertEquals(matches.get(hit).value, r.get(hit).value, 0f);
assertEquals(matches.get(hit).value, r.get(hit).value);
}
}
IOUtils.close(a, tempDir);

View File

@ -46,37 +46,37 @@ public class TestWFSTCompletion extends LuceneTestCase {
suggester.lookup(TestUtil.stringToCharSequence("f", random), false, 2);
assertEquals(1, results.size());
assertEquals("foo", results.get(0).key.toString());
assertEquals(50, results.get(0).value, 0.01F);
assertEquals(50, results.get(0).value);
// make sure we don't get a dup exact suggestion:
results = suggester.lookup(TestUtil.stringToCharSequence("foo", random), false, 2);
assertEquals(1, results.size());
assertEquals("foo", results.get(0).key.toString());
assertEquals(50, results.get(0).value, 0.01F);
assertEquals(50, results.get(0).value);
// top N of 1 for 'bar': we return this even though barbar is higher
results = suggester.lookup(TestUtil.stringToCharSequence("bar", random), false, 1);
assertEquals(1, results.size());
assertEquals("bar", results.get(0).key.toString());
assertEquals(10, results.get(0).value, 0.01F);
assertEquals(10, results.get(0).value);
// top N Of 2 for 'b'
results = suggester.lookup(TestUtil.stringToCharSequence("b", random), false, 2);
assertEquals(2, results.size());
assertEquals("barbar", results.get(0).key.toString());
assertEquals(12, results.get(0).value, 0.01F);
assertEquals(12, results.get(0).value);
assertEquals("bar", results.get(1).key.toString());
assertEquals(10, results.get(1).value, 0.01F);
assertEquals(10, results.get(1).value);
// top N of 3 for 'ba'
results = suggester.lookup(TestUtil.stringToCharSequence("ba", random), false, 3);
assertEquals(3, results.size());
assertEquals("barbar", results.get(0).key.toString());
assertEquals(12, results.get(0).value, 0.01F);
assertEquals(12, results.get(0).value);
assertEquals("bar", results.get(1).key.toString());
assertEquals(10, results.get(1).value, 0.01F);
assertEquals(10, results.get(1).value);
assertEquals("barbara", results.get(2).key.toString());
assertEquals(6, results.get(2).value, 0.01F);
assertEquals(6, results.get(2).value);
tempDir.close();
}
@ -189,7 +189,7 @@ public class TestWFSTCompletion extends LuceneTestCase {
new Comparator<LookupResult>() {
@Override
public int compare(LookupResult left, LookupResult right) {
int cmp = Float.compare(right.value, left.value);
int cmp = Long.compare(right.value, left.value);
if (cmp == 0) {
return left.compareTo(right);
} else {
@ -206,7 +206,7 @@ public class TestWFSTCompletion extends LuceneTestCase {
for (int hit = 0; hit < r.size(); hit++) {
// System.out.println(" check hit " + hit);
assertEquals(matches.get(hit).key.toString(), r.get(hit).key.toString());
assertEquals(matches.get(hit).value, r.get(hit).value, 0f);
assertEquals(matches.get(hit).value, r.get(hit).value);
}
}
tempDir.close();

View File

@ -1,6 +1,6 @@
com.carrotsearch.randomizedtesting:*=2.7.6
com.carrotsearch:hppc=0.9.0
com.google.errorprone:*=2.4.0
com.google.errorprone:*=2.10.0
com.ibm.icu:icu4j=70.1
commons-codec:commons-codec=1.13
io.sgr:s2-geometry-library-java=1.0.0