Skip to content

Apache Lucene open-source search software

Revert "Ensure that FilterXxx properly delegate to the decorated instances (#15469)"

Dawid Weiss3eb7ea9be751
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 8013a2d6db2..6fa42526f92 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -56,8 +56,6 @@ API Changes
* GITHUB#14615 : Remove unnecessary public methods in FuzzySet (Greg Miller)
-* GITHUB#15452: Ensure that Filter classes properly delegate to the decorated instances (Benjamin Lerer)
-
* GITHUB#15507: Expose MergeRateLimiter in ConcurrentMergeScheduler.runOnMergeFinished hook.
The runOnMergeFinished method signature now includes OneMerge and MergeRateLimiter parameters,
enabling applications to monitor merge performance metrics like pause time, throttling behavior,
diff --git a/lucene/core/src/java/org/apache/lucene/index/FilterBinaryDocValues.java b/lucene/core/src/java/org/apache/lucene/index/FilterBinaryDocValues.java
index 72db1522be9..fac56fae5ca 100644
--- a/lucene/core/src/java/org/apache/lucene/index/FilterBinaryDocValues.java
+++ b/lucene/core/src/java/org/apache/lucene/index/FilterBinaryDocValues.java
@@ -20,7 +20,6 @@ package org.apache.lucene.index;
import java.io.IOException;
import java.util.Objects;
import org.apache.lucene.util.BytesRef;
-import org.apache.lucene.util.FixedBitSet;
/** Delegates all methods to a wrapped {@link BinaryDocValues}. */
public abstract class FilterBinaryDocValues extends BinaryDocValues {
@@ -63,14 +62,4 @@ public abstract class FilterBinaryDocValues extends BinaryDocValues {
public BytesRef binaryValue() throws IOException {
return in.binaryValue();
}
-
- @Override
- public void intoBitSet(int upTo, FixedBitSet bitSet, int offset) throws IOException {
- in.intoBitSet(upTo, bitSet, offset);
- }
-
- @Override
- public int docIDRunEnd() throws IOException {
- return in.docIDRunEnd();
- }
}
diff --git a/lucene/core/src/java/org/apache/lucene/index/FilterCodecReader.java b/lucene/core/src/java/org/apache/lucene/index/FilterCodecReader.java
index 3cb3d74d128..737aedce204 100644
--- a/lucene/core/src/java/org/apache/lucene/index/FilterCodecReader.java
+++ b/lucene/core/src/java/org/apache/lucene/index/FilterCodecReader.java
@@ -26,7 +26,6 @@ import org.apache.lucene.codecs.PointsReader;
import org.apache.lucene.codecs.StoredFieldsReader;
import org.apache.lucene.codecs.TermVectorsReader;
import org.apache.lucene.util.Bits;
-import org.apache.lucene.util.LiveDocs;
/**
* A <code>FilterCodecReader</code> contains another CodecReader, which it uses as its basic source
@@ -131,16 +130,6 @@ public abstract class FilterCodecReader extends CodecReader {
in.checkIntegrity();
}
- @Override
- public LiveDocs getLiveDocsWithDeletedIterator() {
- return in.getLiveDocsWithDeletedIterator();
- }
-
- @Override
- public boolean hasDeletions() {
- return in.hasDeletions();
- }
-
/** Returns the wrapped {@link CodecReader}. */
public CodecReader getDelegate() {
return in;
diff --git a/lucene/core/src/java/org/apache/lucene/index/FilterDirectoryReader.java b/lucene/core/src/java/org/apache/lucene/index/FilterDirectoryReader.java
index 5dfce7b03f1..c286dfc34e3 100644
--- a/lucene/core/src/java/org/apache/lucene/index/FilterDirectoryReader.java
+++ b/lucene/core/src/java/org/apache/lucene/index/FilterDirectoryReader.java
@@ -163,11 +163,6 @@ public abstract class FilterDirectoryReader extends DirectoryReader {
in.close();
}
- @Override
- public boolean hasDeletions() {
- return in.hasDeletions();
- }
-
/** Returns the wrapped {@link DirectoryReader}. */
public DirectoryReader getDelegate() {
return in;
diff --git a/lucene/core/src/java/org/apache/lucene/index/FilterLeafReader.java b/lucene/core/src/java/org/apache/lucene/index/FilterLeafReader.java
index ff529188514..174072407a8 100644
--- a/lucene/core/src/java/org/apache/lucene/index/FilterLeafReader.java
+++ b/lucene/core/src/java/org/apache/lucene/index/FilterLeafReader.java
@@ -19,16 +19,12 @@ package org.apache.lucene.index;
import java.io.IOException;
import java.util.Iterator;
import org.apache.lucene.search.AcceptDocs;
-import org.apache.lucene.search.DocAndFloatFeatureBuffer;
import org.apache.lucene.search.KnnCollector;
import org.apache.lucene.util.AttributeSource;
import org.apache.lucene.util.Bits;
import org.apache.lucene.util.BytesRef;
-import org.apache.lucene.util.FixedBitSet;
import org.apache.lucene.util.IOBooleanSupplier;
-import org.apache.lucene.util.LiveDocs;
import org.apache.lucene.util.Unwrappable;
-import org.apache.lucene.util.automaton.CompiledAutomaton;
/**
* A <code>FilterLeafReader</code> contains another LeafReader, which it uses as its basic source of
@@ -163,21 +159,6 @@ public abstract class FilterLeafReader extends LeafReader {
public Object getStats() throws IOException {
return in.getStats();
}
-
- @Override
- public TermsEnum intersect(CompiledAutomaton compiled, BytesRef startTerm) throws IOException {
- return in.intersect(compiled, startTerm);
- }
-
- @Override
- public BytesRef getMin() throws IOException {
- return in.getMin();
- }
-
- @Override
- public BytesRef getMax() throws IOException {
- return in.getMax();
- }
}
/** Base class for filtering {@link TermsEnum} implementations. */
@@ -336,21 +317,6 @@ public abstract class FilterLeafReader extends LeafReader {
public PostingsEnum unwrap() {
return in;
}
-
- @Override
- public void nextPostings(int upTo, DocAndFloatFeatureBuffer buffer) throws IOException {
- in.nextPostings(upTo, buffer);
- }
-
- @Override
- public void intoBitSet(int upTo, FixedBitSet bitSet, int offset) throws IOException {
- in.intoBitSet(upTo, bitSet, offset);
- }
-
- @Override
- public int docIDRunEnd() throws IOException {
- return in.docIDRunEnd();
- }
}
/** The underlying LeafReader. */
@@ -508,16 +474,6 @@ public abstract class FilterLeafReader extends LeafReader {
in.checkIntegrity();
}
- @Override
- public boolean hasDeletions() {
- return in.hasDeletions();
- }
-
- @Override
- public LiveDocs getLiveDocsWithDeletedIterator() {
- return in.getLiveDocsWithDeletedIterator();
- }
-
/** Returns the wrapped {@link LeafReader}. */
public LeafReader getDelegate() {
return in;
diff --git a/lucene/core/src/java/org/apache/lucene/index/FilterNumericDocValues.java b/lucene/core/src/java/org/apache/lucene/index/FilterNumericDocValues.java
index 2f7d5c0d883..3ece4900bf1 100644
--- a/lucene/core/src/java/org/apache/lucene/index/FilterNumericDocValues.java
+++ b/lucene/core/src/java/org/apache/lucene/index/FilterNumericDocValues.java
@@ -19,7 +19,6 @@ package org.apache.lucene.index;
import java.io.IOException;
import java.util.Objects;
-import org.apache.lucene.util.FixedBitSet;
/** Delegates all methods to a wrapped {@link NumericDocValues}. */
public abstract class FilterNumericDocValues extends NumericDocValues {
@@ -62,20 +61,4 @@ public abstract class FilterNumericDocValues extends NumericDocValues {
public long longValue() throws IOException {
return in.longValue();
}
-
- @Override
- public void longValues(int size, int[] docs, long[] values, long defaultValue)
- throws IOException {
- in.longValues(size, docs, values, defaultValue);
- }
-
- @Override
- public void intoBitSet(int upTo, FixedBitSet bitSet, int offset) throws IOException {
- in.intoBitSet(upTo, bitSet, offset);
- }
-
- @Override
- public int docIDRunEnd() throws IOException {
- return in.docIDRunEnd();
- }
}
diff --git a/lucene/core/src/java/org/apache/lucene/index/FilterSortedDocValues.java b/lucene/core/src/java/org/apache/lucene/index/FilterSortedDocValues.java
index 66c0fa02969..01c8e3edfca 100644
--- a/lucene/core/src/java/org/apache/lucene/index/FilterSortedDocValues.java
+++ b/lucene/core/src/java/org/apache/lucene/index/FilterSortedDocValues.java
@@ -19,7 +19,6 @@ package org.apache.lucene.index;
import java.io.IOException;
import java.util.Objects;
import org.apache.lucene.util.BytesRef;
-import org.apache.lucene.util.FixedBitSet;
import org.apache.lucene.util.automaton.CompiledAutomaton;
/** Delegates all methods to a wrapped {@link SortedDocValues}. */
@@ -88,14 +87,4 @@ public abstract class FilterSortedDocValues extends SortedDocValues {
public long cost() {
return in.cost();
}
-
- @Override
- public void intoBitSet(int upTo, FixedBitSet bitSet, int offset) throws IOException {
- in.intoBitSet(upTo, bitSet, offset);
- }
-
- @Override
- public int docIDRunEnd() throws IOException {
- return in.docIDRunEnd();
- }
}
diff --git a/lucene/core/src/java/org/apache/lucene/index/FilterSortedNumericDocValues.java b/lucene/core/src/java/org/apache/lucene/index/FilterSortedNumericDocValues.java
index ff50a8a9b9c..7d2c7f1b280 100644
--- a/lucene/core/src/java/org/apache/lucene/index/FilterSortedNumericDocValues.java
+++ b/lucene/core/src/java/org/apache/lucene/index/FilterSortedNumericDocValues.java
@@ -18,7 +18,6 @@ package org.apache.lucene.index;
import java.io.IOException;
import java.util.Objects;
-import org.apache.lucene.util.FixedBitSet;
/** Delegates all methods to a wrapped {@link SortedNumericDocValues}. */
public abstract class FilterSortedNumericDocValues extends SortedNumericDocValues {
@@ -66,14 +65,4 @@ public abstract class FilterSortedNumericDocValues extends SortedNumericDocValue
public long cost() {
return in.cost();
}
-
- @Override
- public void intoBitSet(int upTo, FixedBitSet bitSet, int offset) throws IOException {
- in.intoBitSet(upTo, bitSet, offset);
- }
-
- @Override
- public int docIDRunEnd() throws IOException {
- return in.docIDRunEnd();
- }
}
diff --git a/lucene/core/src/java/org/apache/lucene/index/FilterSortedSetDocValues.java b/lucene/core/src/java/org/apache/lucene/index/FilterSortedSetDocValues.java
index 56b88d82b1d..92c5d344e57 100644
--- a/lucene/core/src/java/org/apache/lucene/index/FilterSortedSetDocValues.java
+++ b/lucene/core/src/java/org/apache/lucene/index/FilterSortedSetDocValues.java
@@ -19,7 +19,6 @@ package org.apache.lucene.index;
import java.io.IOException;
import java.util.Objects;
import org.apache.lucene.util.BytesRef;
-import org.apache.lucene.util.FixedBitSet;
import org.apache.lucene.util.automaton.CompiledAutomaton;
/** Delegates all methods to a wrapped {@link SortedSetDocValues}. */
@@ -93,14 +92,4 @@ public class FilterSortedSetDocValues extends SortedSetDocValues {
public long cost() {
return in.cost();
}
-
- @Override
- public void intoBitSet(int upTo, FixedBitSet bitSet, int offset) throws IOException {
- in.intoBitSet(upTo, bitSet, offset);
- }
-
- @Override
- public int docIDRunEnd() throws IOException {
- return in.docIDRunEnd();
- }
}
diff --git a/lucene/core/src/java/org/apache/lucene/search/BooleanScorerSupplier.java b/lucene/core/src/java/org/apache/lucene/search/BooleanScorerSupplier.java
index 1799fe7d7b1..480a524de54 100644
--- a/lucene/core/src/java/org/apache/lucene/search/BooleanScorerSupplier.java
+++ b/lucene/core/src/java/org/apache/lucene/search/BooleanScorerSupplier.java
@@ -428,12 +428,12 @@ final class BooleanScorerSupplier extends ScorerSupplier {
conjunctionScorer =
new FilterScorer(inner) {
@Override
- public float score() {
+ public float score() throws IOException {
return 0f;
}
@Override
- public float getMaxScore(int upTo) {
+ public float getMaxScore(int upTo) throws IOException {
return 0f;
}
};
@@ -477,25 +477,19 @@ final class BooleanScorerSupplier extends ScorerSupplier {
}
if (requiredScoring.isEmpty()) {
- // Scores are needed, but we only have a filter clause
- // BooleanWeight expects that calling score(), getMaxScore() and advanceShallow()
- // is ok so we need to override those methods to stop them
- // from being propagated.
+ // Scores are needed but we only have a filter clause
+ // BooleanWeight expects that calling score() is ok so we need to wrap
+ // to prevent score() from being propagated
return new FilterScorer(req) {
@Override
- public float score() {
+ public float score() throws IOException {
return 0f;
}
@Override
- public float getMaxScore(int upTo) {
+ public float getMaxScore(int upTo) throws IOException {
return 0f;
}
-
- @Override
- public int advanceShallow(int target) {
- return DocIdSetIterator.NO_MORE_DOCS;
- }
};
}
diff --git a/lucene/core/src/java/org/apache/lucene/search/FilterScorable.java b/lucene/core/src/java/org/apache/lucene/search/FilterScorable.java
index 3bbf80813d7..890a3f3c2d5 100644
--- a/lucene/core/src/java/org/apache/lucene/search/FilterScorable.java
+++ b/lucene/core/src/java/org/apache/lucene/search/FilterScorable.java
@@ -49,14 +49,4 @@ public class FilterScorable extends Scorable {
public Collection<ChildScorable> getChildren() throws IOException {
return Collections.singletonList(new ChildScorable(in, "FILTER"));
}
-
- @Override
- public float smoothingScore(int docId) throws IOException {
- return in.smoothingScore(docId);
- }
-
- @Override
- public void setMinCompetitiveScore(float minScore) throws IOException {
- in.setMinCompetitiveScore(minScore);
- }
}
diff --git a/lucene/core/src/java/org/apache/lucene/search/FilterScorer.java b/lucene/core/src/java/org/apache/lucene/search/FilterScorer.java
index e02225d5cdb..9ea6fad407e 100644
--- a/lucene/core/src/java/org/apache/lucene/search/FilterScorer.java
+++ b/lucene/core/src/java/org/apache/lucene/search/FilterScorer.java
@@ -17,9 +17,6 @@
package org.apache.lucene.search;
import java.io.IOException;
-import java.util.Collection;
-import java.util.Collections;
-import org.apache.lucene.util.Bits;
import org.apache.lucene.util.Unwrappable;
/**
@@ -67,32 +64,6 @@ public abstract class FilterScorer extends Scorer implements Unwrappable<Scorer>
return in.twoPhaseIterator();
}
- @Override
- public void setMinCompetitiveScore(float minScore) throws IOException {
- in.setMinCompetitiveScore(minScore);
- }
-
- @Override
- public Collection<ChildScorable> getChildren() throws IOException {
- return Collections.singletonList(new ChildScorable(in, "FILTER"));
- }
-
- @Override
- public float smoothingScore(int docId) throws IOException {
- return in.smoothingScore(docId);
- }
-
- @Override
- public void nextDocsAndScores(int upTo, Bits liveDocs, DocAndFloatFeatureBuffer buffer)
- throws IOException {
- in.nextDocsAndScores(upTo, liveDocs, buffer);
- }
-
- @Override
- public int advanceShallow(int target) throws IOException {
- return in.advanceShallow(target);
- }
-
@Override
public Scorer unwrap() {
return in;
diff --git a/lucene/core/src/java/org/apache/lucene/search/FilterWeight.java b/lucene/core/src/java/org/apache/lucene/search/FilterWeight.java
index 4d67cd0e8ed..16bb75ef406 100644
--- a/lucene/core/src/java/org/apache/lucene/search/FilterWeight.java
+++ b/lucene/core/src/java/org/apache/lucene/search/FilterWeight.java
@@ -67,9 +67,4 @@ public abstract class FilterWeight extends Weight {
public ScorerSupplier scorerSupplier(LeafReaderContext context) throws IOException {
return in.scorerSupplier(context);
}
-
- @Override
- public int count(LeafReaderContext context) throws IOException {
- return in.count(context);
- }
}
diff --git a/lucene/core/src/java/org/apache/lucene/store/FilterIndexInput.java b/lucene/core/src/java/org/apache/lucene/store/FilterIndexInput.java
index 7448a2d8fec..933701b3c3d 100644
--- a/lucene/core/src/java/org/apache/lucene/store/FilterIndexInput.java
+++ b/lucene/core/src/java/org/apache/lucene/store/FilterIndexInput.java
@@ -17,9 +17,6 @@
package org.apache.lucene.store;
import java.io.IOException;
-import java.util.Map;
-import java.util.Optional;
-import java.util.Set;
import java.util.concurrent.CopyOnWriteArrayList;
import org.apache.lucene.internal.tests.TestSecrets;
@@ -80,12 +77,6 @@ public class FilterIndexInput extends IndexInput {
in.close();
}
- @Override
- public IndexInput clone() {
- throw new RuntimeException(
- "Clone not implemented by the filter class: " + getClass().getName());
- }
-
@Override
public long getFilePointer() {
return in.getFilePointer();
@@ -115,105 +106,4 @@ public class FilterIndexInput extends IndexInput {
public void readBytes(byte[] b, int offset, int len) throws IOException {
in.readBytes(b, offset, len);
}
-
- @Override
- public Set<String> readSetOfStrings() throws IOException {
- return in.readSetOfStrings();
- }
-
- @Override
- public Map<String, String> readMapOfStrings() throws IOException {
- return in.readMapOfStrings();
- }
-
- @Override
- public String readString() throws IOException {
- return in.readString();
- }
-
- @Override
- public long readZLong() throws IOException {
- return in.readZLong();
- }
-
- @Override
- public long readVLong() throws IOException {
- return in.readVLong();
- }
-
- @Override
- public void readFloats(float[] floats, int offset, int len) throws IOException {
- in.readFloats(floats, offset, len);
- }
-
- @Override
- public void readInts(int[] dst, int offset, int length) throws IOException {
- in.readInts(dst, offset, length);
- }
-
- @Override
- public void readLongs(long[] dst, int offset, int length) throws IOException {
- in.readLongs(dst, offset, length);
- }
-
- @Override
- public long readLong() throws IOException {
- return in.readLong();
- }
-
- @Override
- public int readZInt() throws IOException {
- return in.readZInt();
- }
-
- @Override
- public int readVInt() throws IOException {
- return in.readVInt();
- }
-
- @Override
- public int readInt() throws IOException {
- return in.readInt();
- }
-
- @Override
- public short readShort() throws IOException {
- return in.readShort();
- }
-
- @Override
- public void readBytes(byte[] b, int offset, int len, boolean useBuffer) throws IOException {
- in.readBytes(b, offset, len, useBuffer);
- }
-
- @Override
- public void prefetch(long offset, long length) throws IOException {
- in.prefetch(offset, length);
- }
-
- @Override
- public RandomAccessInput randomAccessSlice(long offset, long length) throws IOException {
- return in.randomAccessSlice(offset, length);
- }
-
- @Override
- public void updateIOContext(IOContext context) throws IOException {
- in.updateIOContext(context);
- }
-
- @Override
- public Optional<Boolean> isLoaded() {
- return in.isLoaded();
- }
-
- @Override
- public IndexInput slice(String sliceDescription, long offset, long length, IOContext context)
- throws IOException {
- return in.slice(sliceDescription, offset, length, context);
- }
-
- @Override
- public void skipBytes(long numBytes) throws IOException {
- in.skipBytes(numBytes);
- }
}
diff --git a/lucene/core/src/java/org/apache/lucene/store/FilterIndexOutput.java b/lucene/core/src/java/org/apache/lucene/store/FilterIndexOutput.java
index 2511f4a523b..1faec626d08 100644
--- a/lucene/core/src/java/org/apache/lucene/store/FilterIndexOutput.java
+++ b/lucene/core/src/java/org/apache/lucene/store/FilterIndexOutput.java
@@ -18,8 +18,6 @@
package org.apache.lucene.store;
import java.io.IOException;
-import java.util.Map;
-import java.util.Set;
/**
* IndexOutput implementation that delegates calls to another directory. This class can be used to
@@ -59,11 +57,6 @@ public class FilterIndexOutput extends IndexOutput {
return out;
}
- @Override
- public String getName() {
- return out.getName();
- }
-
@Override
public void close() throws IOException {
out.close();
@@ -88,55 +81,4 @@ public class FilterIndexOutput extends IndexOutput {
public void writeBytes(byte[] b, int offset, int length) throws IOException {
out.writeBytes(b, offset, length);
}
-
- @Override
- public void writeBytes(byte[] b, int length) throws IOException {
- out.writeBytes(b, length);
- }
-
- @Override
- public void writeInt(int i) throws IOException {
- out.writeInt(i);
- }
-
- @Override
- public void writeShort(short i) throws IOException {
- out.writeShort(i);
- }
-
- @Override
- public void writeLong(long i) throws IOException {
- out.writeLong(i);
- }
-
- @Override
- public void writeString(String s) throws IOException {
- out.writeString(s);
- }
-
- @Override
- public void copyBytes(DataInput input, long numBytes) throws IOException {
- out.copyBytes(input, numBytes);
- }
-
- @Override
- public void writeMapOfStrings(Map<String, String> map) throws IOException {
- out.writeMapOfStrings(map);
- }
-
- @Override
- public void writeSetOfStrings(Set<String> set) throws IOException {
- out.writeSetOfStrings(set);
- }
-
- @Override
- public void writeGroupVInts(int[] values, int limit) throws IOException {
- out.writeGroupVInts(values, limit);
- }
-
- @Override
- @Deprecated
- public void writeGroupVInts(long[] values, int limit) throws IOException {
- out.writeGroupVInts(values, limit);
- }
}
diff --git a/lucene/core/src/test/org/apache/lucene/codecs/TestFilterCodec.java b/lucene/core/src/test/org/apache/lucene/codecs/TestFilterCodec.java
deleted file mode 100644
index 23208a883bb..00000000000
--- a/lucene/core/src/test/org/apache/lucene/codecs/TestFilterCodec.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.lucene.codecs;
-
-import org.apache.lucene.tests.util.LuceneTestCase;
-import org.junit.Test;
-
-public class TestFilterCodec extends LuceneTestCase {
-
- @Test
- public void testDeclaredMethodsOverridden() {
- assertDelegatorOverridesAllRequiredMethods(FilterCodec.class);
- }
-}
diff --git a/lucene/core/src/test/org/apache/lucene/codecs/lucene90/TestLucene90StoredFieldsFormat.java b/lucene/core/src/test/org/apache/lucene/codecs/lucene90/TestLucene90StoredFieldsFormat.java
index 8d612b9d918..ae9c6d7b53f 100644
--- a/lucene/core/src/test/org/apache/lucene/codecs/lucene90/TestLucene90StoredFieldsFormat.java
+++ b/lucene/core/src/test/org/apache/lucene/codecs/lucene90/TestLucene90StoredFieldsFormat.java
@@ -80,13 +80,6 @@ public class TestLucene90StoredFieldsFormat extends BaseStoredFieldsFormatTestCa
public IndexInput slice(String sliceDescription, long offset, long length) throws IOException {
return new CountingPrefetchIndexInput(in.slice(sliceDescription, offset, length), counter);
}
-
- @Override
- public IndexInput slice(String sliceDescription, long offset, long length, IOContext context)
- throws IOException {
- return new CountingPrefetchIndexInput(
- in.slice(sliceDescription, offset, length, context), counter);
- }
}
public void testSkipRedundantPrefetches() throws IOException {
diff --git a/lucene/core/src/test/org/apache/lucene/codecs/lucene90/TestLucene90TermVectorsFormat.java b/lucene/core/src/test/org/apache/lucene/codecs/lucene90/TestLucene90TermVectorsFormat.java
index 2aec6afc5e4..8cc6dda1c1d 100644
--- a/lucene/core/src/test/org/apache/lucene/codecs/lucene90/TestLucene90TermVectorsFormat.java
+++ b/lucene/core/src/test/org/apache/lucene/codecs/lucene90/TestLucene90TermVectorsFormat.java
@@ -78,13 +78,6 @@ public class TestLucene90TermVectorsFormat extends BaseTermVectorsFormatTestCase
return new CountingPrefetchIndexInput(in.clone(), counter);
}
- @Override
- public IndexInput slice(String sliceDescription, long offset, long length, IOContext context)
- throws IOException {
- return new CountingPrefetchIndexInput(
- in.slice(sliceDescription, offset, length, context), counter);
- }
-
@Override
public IndexInput slice(String sliceDescription, long offset, long length) throws IOException {
return new CountingPrefetchIndexInput(in.slice(sliceDescription, offset, length), counter);
diff --git a/lucene/core/src/test/org/apache/lucene/index/TestFilterBinaryDocValues.java b/lucene/core/src/test/org/apache/lucene/index/TestFilterBinaryDocValues.java
deleted file mode 100644
index 29637c551a4..00000000000
--- a/lucene/core/src/test/org/apache/lucene/index/TestFilterBinaryDocValues.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.lucene.index;
-
-import org.apache.lucene.tests.util.LuceneTestCase;
-import org.junit.Test;
-
-public class TestFilterBinaryDocValues extends LuceneTestCase {
-
- @Test
- public void testDeclaredMethodsOverridden() {
- assertDelegatorOverridesAllRequiredMethods(FilterBinaryDocValues.class);
- }
-}
diff --git a/lucene/core/src/test/org/apache/lucene/index/TestFilterCodecReader.java b/lucene/core/src/test/org/apache/lucene/index/TestFilterCodecReader.java
index 66fa2ac22b0..e9ee2f32627 100644
--- a/lucene/core/src/test/org/apache/lucene/index/TestFilterCodecReader.java
+++ b/lucene/core/src/test/org/apache/lucene/index/TestFilterCodecReader.java
@@ -17,6 +17,8 @@
package org.apache.lucene.index;
import java.io.IOException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
import org.apache.lucene.document.Document;
import org.apache.lucene.store.Directory;
import org.apache.lucene.tests.util.LuceneTestCase;
@@ -24,7 +26,8 @@ import org.apache.lucene.tests.util.LuceneTestCase;
public class TestFilterCodecReader extends LuceneTestCase {
public void testDeclaredMethodsOverridden() throws Exception {
- assertDelegatorOverridesAllRequiredMethods(FilterCodecReader.class);
+ final Class<?> subClass = FilterCodecReader.class;
+ implTestDeclaredMethodsOverridden(subClass.getSuperclass(), subClass);
}
public void testGetDelegate() throws IOException {
@@ -41,4 +44,25 @@ public class TestFilterCodecReader extends LuceneTestCase {
}
}
}
+
+ private void implTestDeclaredMethodsOverridden(Class<?> superClass, Class<?> subClass)
+ throws Exception {
+ for (final Method superClassMethod : superClass.getDeclaredMethods()) {
+ final int modifiers = superClassMethod.getModifiers();
+ if (Modifier.isPrivate(modifiers)) continue;
+ if (Modifier.isFinal(modifiers)) continue;
+ if (Modifier.isStatic(modifiers)) continue;
+ try {
+ final Method subClassMethod =
+ subClass.getDeclaredMethod(
+ superClassMethod.getName(), superClassMethod.getParameterTypes());
+ assertEquals(
+ "getReturnType() difference",
+ superClassMethod.getReturnType(),
+ subClassMethod.getReturnType());
+ } catch (NoSuchMethodException _) {
+ fail(subClass + " needs to override '" + superClassMethod + "'");
+ }
+ }
+ }
}
diff --git a/lucene/core/src/test/org/apache/lucene/index/TestFilterDirectoryReader.java b/lucene/core/src/test/org/apache/lucene/index/TestFilterDirectoryReader.java
index 5ab73e93c9d..6bd144dc0ad 100644
--- a/lucene/core/src/test/org/apache/lucene/index/TestFilterDirectoryReader.java
+++ b/lucene/core/src/test/org/apache/lucene/index/TestFilterDirectoryReader.java
@@ -27,7 +27,6 @@ import org.apache.lucene.index.FilterDirectoryReader.SubReaderWrapper;
import org.apache.lucene.store.Directory;
import org.apache.lucene.tests.util.LuceneTestCase;
import org.apache.lucene.util.IOUtils;
-import org.junit.Test;
public class TestFilterDirectoryReader extends LuceneTestCase {
@@ -198,9 +197,4 @@ public class TestFilterDirectoryReader extends LuceneTestCase {
w.close();
dir.close();
}
-
- @Test
- public void testOverrides() throws Exception {
- assertDelegatorOverridesAllRequiredMethods(FilterDirectoryReader.class);
- }
}
diff --git a/lucene/core/src/test/org/apache/lucene/index/TestFilterIndexInput.java b/lucene/core/src/test/org/apache/lucene/index/TestFilterIndexInput.java
index 1f77fa76dab..d43b580f601 100644
--- a/lucene/core/src/test/org/apache/lucene/index/TestFilterIndexInput.java
+++ b/lucene/core/src/test/org/apache/lucene/index/TestFilterIndexInput.java
@@ -17,6 +17,8 @@
package org.apache.lucene.index;
import java.io.IOException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
import java.util.Random;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.FSDirectory;
@@ -59,7 +61,24 @@ public class TestFilterIndexInput extends TestIndexInput {
@Test
public void testOverrides() {
- assertDelegatorOverridesAllRequiredMethods(FilterIndexInput.class);
+ for (Method m : FilterIndexInput.class.getMethods()) {
+ if (m.getName().contains("clone")) {
+ // special case
+ continue;
+ }
+ if (m.getDeclaringClass() == FilterIndexInput.class) {
+ // verify that only abstract methods are overridden
+ Method indexInputMethod;
+ try {
+ indexInputMethod = IndexInput.class.getMethod(m.getName(), m.getParameterTypes());
+ assertTrue(
+ "Non-abstract method " + m.getName() + " is overridden",
+ Modifier.isAbstract(indexInputMethod.getModifiers()));
+ } catch (Exception e) {
+ assertTrue(e instanceof NoSuchMethodException);
+ }
+ }
+ }
}
public void testUnwrap() throws IOException {
diff --git a/lucene/core/src/test/org/apache/lucene/index/TestFilterIndexOutput.java b/lucene/core/src/test/org/apache/lucene/index/TestFilterIndexOutput.java
deleted file mode 100644
index 034771403d7..00000000000
--- a/lucene/core/src/test/org/apache/lucene/index/TestFilterIndexOutput.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.lucene.index;
-
-import org.apache.lucene.store.FilterIndexOutput;
-import org.apache.lucene.tests.util.LuceneTestCase;
-import org.junit.Test;
-
-public class TestFilterIndexOutput extends LuceneTestCase {
-
- @Test
- public void testOverrides() {
- assertDelegatorOverridesAllRequiredMethods(FilterIndexOutput.class);
- }
-}
diff --git a/lucene/core/src/test/org/apache/lucene/index/TestFilterLeafReader.java b/lucene/core/src/test/org/apache/lucene/index/TestFilterLeafReader.java
index 4435483bd46..be1715279fd 100644
--- a/lucene/core/src/test/org/apache/lucene/index/TestFilterLeafReader.java
+++ b/lucene/core/src/test/org/apache/lucene/index/TestFilterLeafReader.java
@@ -17,8 +17,8 @@
package org.apache.lucene.index;
import java.io.IOException;
-import java.util.Set;
-import java.util.function.Consumer;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.search.DocIdSetIterator;
@@ -180,16 +180,39 @@ public class TestFilterLeafReader extends LuceneTestCase {
target.close();
}
+ private static void checkOverrideMethods(Class<?> clazz)
+ throws NoSuchMethodException, SecurityException {
+ final Class<?> superClazz = clazz.getSuperclass();
+ for (Method m : superClazz.getMethods()) {
+ final int mods = m.getModifiers();
+ if (Modifier.isStatic(mods)
+ || Modifier.isAbstract(mods)
+ || Modifier.isFinal(mods)
+ || m.isSynthetic()
+ || m.getName().equals("attributes")
+ || m.getName().equals("getStats")) {
+ continue;
+ }
+ // The point of these checks is to ensure that methods that have a default
+ // impl through other methods are not overridden. This makes the number of
+ // methods to override to have a working impl minimal and prevents from some
+ // traps: for example, think about having getCoreCacheKey delegate to the
+ // filtered impl by default
+ final Method subM = clazz.getMethod(m.getName(), m.getParameterTypes());
+ if (subM.getDeclaringClass() == clazz
+ && m.getDeclaringClass() != Object.class
+ && m.getDeclaringClass() != subM.getDeclaringClass()) {
+ fail(clazz + " overrides " + m + " although it has a default impl");
+ }
+ }
+ }
+
public void testOverrideMethods() throws Exception {
- assertDelegatorOverridesAllRequiredMethods(FilterLeafReader.class);
- assertDelegatorOverridesAllRequiredMethods(
- FilterLeafReader.FilterFields.class,
- Set.of(
- Iterable.class.getMethod("forEach", Consumer.class),
- Iterable.class.getMethod("spliterator")));
- assertDelegatorOverridesAllRequiredMethods(FilterLeafReader.FilterTerms.class);
- assertDelegatorOverridesAllRequiredMethods(FilterLeafReader.FilterTermsEnum.class);
- assertDelegatorOverridesAllRequiredMethods(FilterLeafReader.FilterPostingsEnum.class);
+ checkOverrideMethods(FilterLeafReader.class);
+ checkOverrideMethods(FilterLeafReader.FilterFields.class);
+ checkOverrideMethods(FilterLeafReader.FilterTerms.class);
+ checkOverrideMethods(FilterLeafReader.FilterTermsEnum.class);
+ checkOverrideMethods(FilterLeafReader.FilterPostingsEnum.class);
}
public void testUnwrap() throws IOException {
diff --git a/lucene/core/src/test/org/apache/lucene/index/TestFilterMergePolicy.java b/lucene/core/src/test/org/apache/lucene/index/TestFilterMergePolicy.java
index 872f64fc813..bc979ae07c9 100644
--- a/lucene/core/src/test/org/apache/lucene/index/TestFilterMergePolicy.java
+++ b/lucene/core/src/test/org/apache/lucene/index/TestFilterMergePolicy.java
@@ -16,11 +16,20 @@
*/
package org.apache.lucene.index;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
import org.apache.lucene.tests.util.LuceneTestCase;
public class TestFilterMergePolicy extends LuceneTestCase {
public void testMethodsOverridden() {
- assertDelegatorOverridesAllRequiredMethods(FilterMergePolicy.class);
+ for (Method m : MergePolicy.class.getDeclaredMethods()) {
+ if (Modifier.isFinal(m.getModifiers()) || Modifier.isPrivate(m.getModifiers())) continue;
+ try {
+ FilterMergePolicy.class.getDeclaredMethod(m.getName(), m.getParameterTypes());
+ } catch (NoSuchMethodException _) {
+ fail("FilterMergePolicy needs to override '" + m + "'");
+ }
+ }
}
}
diff --git a/lucene/core/src/test/org/apache/lucene/index/TestFilterNumericDocValues.java b/lucene/core/src/test/org/apache/lucene/index/TestFilterNumericDocValues.java
deleted file mode 100644
index e054c94d2b6..00000000000
--- a/lucene/core/src/test/org/apache/lucene/index/TestFilterNumericDocValues.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.lucene.index;
-
-import org.apache.lucene.tests.util.LuceneTestCase;
-import org.junit.Test;
-
-public class TestFilterNumericDocValues extends LuceneTestCase {
- @Test
- public void testDeclaredMethodsOverridden() {
- assertDelegatorOverridesAllRequiredMethods(FilterNumericDocValues.class);
- }
-}
diff --git a/lucene/core/src/test/org/apache/lucene/index/TestFilterSortedDocValues.java b/lucene/core/src/test/org/apache/lucene/index/TestFilterSortedDocValues.java
deleted file mode 100644
index f09e51d7f3f..00000000000
--- a/lucene/core/src/test/org/apache/lucene/index/TestFilterSortedDocValues.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.lucene.index;
-
-import org.apache.lucene.tests.util.LuceneTestCase;
-import org.junit.Test;
-
-public class TestFilterSortedDocValues extends LuceneTestCase {
-
- @Test
- public void testDeclaredMethodsOverridden() {
- assertDelegatorOverridesAllRequiredMethods(FilterSortedDocValues.class);
- }
-}
diff --git a/lucene/core/src/test/org/apache/lucene/index/TestFilterSortedNumericDocValues.java b/lucene/core/src/test/org/apache/lucene/index/TestFilterSortedNumericDocValues.java
deleted file mode 100644
index dd1d33d4020..00000000000
--- a/lucene/core/src/test/org/apache/lucene/index/TestFilterSortedNumericDocValues.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.lucene.index;
-
-import org.apache.lucene.tests.util.LuceneTestCase;
-import org.junit.Test;
-
-public class TestFilterSortedNumericDocValues extends LuceneTestCase {
-
- @Test
- public void testDeclaredMethodsOverridden() {
- assertDelegatorOverridesAllRequiredMethods(FilterSortedNumericDocValues.class);
- }
-}
diff --git a/lucene/core/src/test/org/apache/lucene/index/TestFilterSortedSetDocValues.java b/lucene/core/src/test/org/apache/lucene/index/TestFilterSortedSetDocValues.java
deleted file mode 100644
index a31870b7fb2..00000000000
--- a/lucene/core/src/test/org/apache/lucene/index/TestFilterSortedSetDocValues.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.lucene.index;
-
-import org.apache.lucene.tests.util.LuceneTestCase;
-import org.junit.Test;
-
-public class TestFilterSortedSetDocValues extends LuceneTestCase {
-
- @Test
- public void testDeclaredMethodsOverridden() {
- assertDelegatorOverridesAllRequiredMethods(FilterSortedSetDocValues.class);
- }
-}
diff --git a/lucene/core/src/test/org/apache/lucene/search/TestFilterCollector.java b/lucene/core/src/test/org/apache/lucene/search/TestFilterCollector.java
deleted file mode 100644
index 245192e25a9..00000000000
--- a/lucene/core/src/test/org/apache/lucene/search/TestFilterCollector.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.lucene.search;
-
-import org.apache.lucene.tests.util.LuceneTestCase;
-import org.junit.Test;
-
-public class TestFilterCollector extends LuceneTestCase {
-
- @Test
- public void testDeclaredMethodsOverridden() {
- assertDelegatorOverridesAllRequiredMethods(FilterCollector.class);
- }
-}
diff --git a/lucene/core/src/test/org/apache/lucene/search/TestFilterScorable.java b/lucene/core/src/test/org/apache/lucene/search/TestFilterScorable.java
deleted file mode 100644
index b8af4d04cd5..00000000000
--- a/lucene/core/src/test/org/apache/lucene/search/TestFilterScorable.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.lucene.search;
-
-import org.apache.lucene.tests.util.LuceneTestCase;
-import org.junit.Test;
-
-public class TestFilterScorable extends LuceneTestCase {
-
- @Test
- public void testDeclaredMethodsOverridden() {
- assertDelegatorOverridesAllRequiredMethods(FilterScorable.class);
- }
-}
diff --git a/lucene/core/src/test/org/apache/lucene/search/TestFilterScorer.java b/lucene/core/src/test/org/apache/lucene/search/TestFilterScorer.java
deleted file mode 100644
index 9575cd36a78..00000000000
--- a/lucene/core/src/test/org/apache/lucene/search/TestFilterScorer.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.lucene.search;
-
-import org.apache.lucene.tests.util.LuceneTestCase;
-import org.junit.Test;
-
-public class TestFilterScorer extends LuceneTestCase {
-
- @Test
- public void testDeclaredMethodsOverridden() {
- assertDelegatorOverridesAllRequiredMethods(FilterScorer.class);
- }
-}
diff --git a/lucene/core/src/test/org/apache/lucene/search/TestFilterWeight.java b/lucene/core/src/test/org/apache/lucene/search/TestFilterWeight.java
index d1778d7a51a..a6177ab892b 100644
--- a/lucene/core/src/test/org/apache/lucene/search/TestFilterWeight.java
+++ b/lucene/core/src/test/org/apache/lucene/search/TestFilterWeight.java
@@ -16,13 +16,59 @@
*/
package org.apache.lucene.search;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.Arrays;
import org.apache.lucene.tests.util.LuceneTestCase;
import org.junit.Test;
public class TestFilterWeight extends LuceneTestCase {
@Test
- public void testDeclaredMethodsOverridden() {
- assertDelegatorOverridesAllRequiredMethods(FilterWeight.class);
+ public void testDeclaredMethodsOverridden() throws Exception {
+ final Class<?> subClass = FilterWeight.class;
+ implTestDeclaredMethodsOverridden(subClass.getSuperclass(), subClass);
+ }
+
+ private void implTestDeclaredMethodsOverridden(Class<?> superClass, Class<?> subClass)
+ throws Exception {
+ for (final Method superClassMethod : superClass.getDeclaredMethods()) {
+ final int modifiers = superClassMethod.getModifiers();
+ if (Modifier.isFinal(modifiers)) continue;
+ if (Modifier.isStatic(modifiers)) continue;
+ if (Arrays.asList("bulkScorer", "count").contains(superClassMethod.getName())) {
+ try {
+ final Method subClassMethod =
+ subClass.getDeclaredMethod(
+ superClassMethod.getName(), superClassMethod.getParameterTypes());
+ fail(
+ subClass
+ + " must not override\n'"
+ + superClassMethod
+ + "'"
+ + " but it does override\n'"
+ + subClassMethod
+ + "'");
+ } catch (NoSuchMethodException _) {
+ /* FilterWeight must not override the bulkScorer method
+ * since as of July 2016 not all deriving classes use the
+ * {code}return in.bulkScorer(content);{code}
+ * implementation that FilterWeight.bulkScorer would use.
+ */
+ continue;
+ }
+ }
+ try {
+ final Method subClassMethod =
+ subClass.getDeclaredMethod(
+ superClassMethod.getName(), superClassMethod.getParameterTypes());
+ assertEquals(
+ "getReturnType() difference",
+ superClassMethod.getReturnType(),
+ subClassMethod.getReturnType());
+ } catch (NoSuchMethodException _) {
+ fail(subClass + " needs to override '" + superClassMethod + "'");
+ }
+ }
}
}
diff --git a/lucene/core/src/test/org/apache/lucene/store/TestFilterDirectory.java b/lucene/core/src/test/org/apache/lucene/store/TestFilterDirectory.java
index d2767d5d62a..6109115c885 100644
--- a/lucene/core/src/test/org/apache/lucene/store/TestFilterDirectory.java
+++ b/lucene/core/src/test/org/apache/lucene/store/TestFilterDirectory.java
@@ -19,6 +19,7 @@ package org.apache.lucene.store;
import java.io.IOException;
import java.lang.reflect.Method;
import java.nio.file.Path;
+import java.util.HashSet;
import java.util.Set;
import org.apache.lucene.tests.store.BaseDirectoryTestCase;
import org.junit.Test;
@@ -34,13 +35,16 @@ public class TestFilterDirectory extends BaseDirectoryTestCase {
public void testOverrides() throws Exception {
// verify that all methods of Directory are overridden by FilterDirectory,
// except those under the 'exclude' list
- Set<Method> exclude =
- Set.of(
- Directory.class.getMethod(
- "copyFrom", Directory.class, String.class, String.class, IOContext.class),
- Directory.class.getMethod("openChecksumInput", String.class));
-
- assertDelegatorOverridesAllRequiredMethods(FilterDirectory.class, exclude);
+ Set<Method> exclude = new HashSet<>();
+ exclude.add(
+ Directory.class.getMethod(
+ "copyFrom", Directory.class, String.class, String.class, IOContext.class));
+ exclude.add(Directory.class.getMethod("openChecksumInput", String.class));
+ for (Method m : FilterDirectory.class.getMethods()) {
+ if (m.getDeclaringClass() == Directory.class) {
+ assertTrue("method " + m.getName() + " not overridden!", exclude.contains(m));
+ }
+ }
}
public void testUnwrap() throws IOException {
diff --git a/lucene/core/src/test/org/apache/lucene/store/TestFilterIndexOutput.java b/lucene/core/src/test/org/apache/lucene/store/TestFilterIndexOutput.java
index 65567878356..2abdf754d59 100644
--- a/lucene/core/src/test/org/apache/lucene/store/TestFilterIndexOutput.java
+++ b/lucene/core/src/test/org/apache/lucene/store/TestFilterIndexOutput.java
@@ -17,6 +17,8 @@
package org.apache.lucene.store;
import java.io.IOException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
import org.junit.Test;
public class TestFilterIndexOutput extends BaseDataOutputTestCase<FilterIndexOutput> {
@@ -36,7 +38,20 @@ public class TestFilterIndexOutput extends BaseDataOutputTestCase<FilterIndexOut
@Test
public void testOverrides() {
- assertDelegatorOverridesAllRequiredMethods(FilterIndexOutput.class);
+ for (Method m : FilterIndexOutput.class.getMethods()) {
+ if (m.getDeclaringClass() == FilterIndexOutput.class) {
+ // verify that only abstract methods are overridden
+ Method indexOutputMethod;
+ try {
+ indexOutputMethod = IndexOutput.class.getMethod(m.getName(), m.getParameterTypes());
+ assertTrue(
+ "Non-abstract method " + m.getName() + " is overridden",
+ Modifier.isAbstract(indexOutputMethod.getModifiers()));
+ } catch (Exception e) {
+ assertTrue(e instanceof NoSuchMethodException);
+ }
+ }
+ }
}
public void testUnwrap() throws IOException {
diff --git a/lucene/join/src/java/org/apache/lucene/search/join/GlobalOrdinalsWithScoreQuery.java b/lucene/join/src/java/org/apache/lucene/search/join/GlobalOrdinalsWithScoreQuery.java
index f5ddd156196..9b118d3cf2e 100644
--- a/lucene/join/src/java/org/apache/lucene/search/join/GlobalOrdinalsWithScoreQuery.java
+++ b/lucene/join/src/java/org/apache/lucene/search/join/GlobalOrdinalsWithScoreQuery.java
@@ -240,12 +240,6 @@ final class GlobalOrdinalsWithScoreQuery extends Query implements Accountable {
// the memory used by the cache
return false;
}
-
- @Override
- public int count(LeafReaderContext context) {
- // Signal we can't compute the exact count in sublinear time.
- return -1;
- }
}
static final class OrdinalMapScorer extends BaseGlobalOrdinalScorer {
diff --git a/lucene/join/src/java/org/apache/lucene/search/join/ToChildBlockJoinQuery.java b/lucene/join/src/java/org/apache/lucene/search/join/ToChildBlockJoinQuery.java
index deee1805dc1..6fd0dc99e6d 100644
--- a/lucene/join/src/java/org/apache/lucene/search/join/ToChildBlockJoinQuery.java
+++ b/lucene/join/src/java/org/apache/lucene/search/join/ToChildBlockJoinQuery.java
@@ -135,12 +135,6 @@ public class ToChildBlockJoinQuery extends Query {
}
return Explanation.noMatch("Not a match");
}
-
- @Override
- public int count(LeafReaderContext context) {
- // Signal we can't compute the exact count in sublinear time.
- return -1;
- }
}
static class ToChildBlockJoinScorer extends Scorer {
diff --git a/lucene/queries/src/java/org/apache/lucene/queries/spans/FilterSpans.java b/lucene/queries/src/java/org/apache/lucene/queries/spans/FilterSpans.java
index 1546831f94a..c29fe79ca1f 100644
--- a/lucene/queries/src/java/org/apache/lucene/queries/spans/FilterSpans.java
+++ b/lucene/queries/src/java/org/apache/lucene/queries/spans/FilterSpans.java
@@ -19,7 +19,6 @@ package org.apache.lucene.queries.spans;
import java.io.IOException;
import java.util.Objects;
import org.apache.lucene.search.TwoPhaseIterator;
-import org.apache.lucene.util.FixedBitSet;
/**
* A {@link Spans} implementation wrapping another spans instance, allowing to filter spans matches
@@ -124,19 +123,9 @@ public abstract class FilterSpans extends Spans {
return in.cost();
}
- @Override
- public void intoBitSet(int upTo, FixedBitSet bitSet, int offset) throws IOException {
- in.intoBitSet(upTo, bitSet, offset);
- }
-
- @Override
- public int docIDRunEnd() throws IOException {
- return in.docIDRunEnd();
- }
-
@Override
public String toString() {
- return "Filter(" + in + ")";
+ return "Filter(" + in.toString() + ")";
}
@Override
diff --git a/lucene/queries/src/test/org/apache/lucene/queries/spans/TestFilterSpans.java b/lucene/queries/src/test/org/apache/lucene/queries/spans/TestFilterSpans.java
index 25a97534045..565885777a6 100644
--- a/lucene/queries/src/test/org/apache/lucene/queries/spans/TestFilterSpans.java
+++ b/lucene/queries/src/test/org/apache/lucene/queries/spans/TestFilterSpans.java
@@ -16,13 +16,19 @@
*/
package org.apache.lucene.queries.spans;
+import java.lang.reflect.Method;
import org.apache.lucene.tests.util.LuceneTestCase;
import org.junit.Test;
public class TestFilterSpans extends LuceneTestCase {
@Test
- public void testOverrides() {
- assertDelegatorOverridesAllRequiredMethods(FilterSpans.class);
+ public void testOverrides() throws Exception {
+ // verify that all methods of Spans are overridden by FilterSpans,
+ for (Method m : FilterSpans.class.getMethods()) {
+ if (m.getDeclaringClass() == Spans.class) {
+ fail("method " + m.getName() + " not overridden!");
+ }
+ }
}
}
diff --git a/lucene/test-framework/src/java/org/apache/lucene/tests/index/AllDeletedFilterReader.java b/lucene/test-framework/src/java/org/apache/lucene/tests/index/AllDeletedFilterReader.java
index 19326636676..12c64290622 100644
--- a/lucene/test-framework/src/java/org/apache/lucene/tests/index/AllDeletedFilterReader.java
+++ b/lucene/test-framework/src/java/org/apache/lucene/tests/index/AllDeletedFilterReader.java
@@ -27,6 +27,7 @@ public class AllDeletedFilterReader extends FilterLeafReader {
public AllDeletedFilterReader(LeafReader in) {
super(in);
liveDocs = new Bits.MatchNoBits(in.maxDoc());
+ assert maxDoc() == 0 || hasDeletions();
}
@Override
@@ -39,11 +40,6 @@ public class AllDeletedFilterReader extends FilterLeafReader {
return 0;
}
- @Override
- public boolean hasDeletions() {
- return maxDoc() > 0;
- }
-
@Override
public CacheHelper getCoreCacheHelper() {
return in.getCoreCacheHelper();
diff --git a/lucene/test-framework/src/java/org/apache/lucene/tests/search/RandomApproximationQuery.java b/lucene/test-framework/src/java/org/apache/lucene/tests/search/RandomApproximationQuery.java
index c03e8883e48..92f247e3754 100644
--- a/lucene/test-framework/src/java/org/apache/lucene/tests/search/RandomApproximationQuery.java
+++ b/lucene/test-framework/src/java/org/apache/lucene/tests/search/RandomApproximationQuery.java
@@ -100,12 +100,6 @@ public class RandomApproximationQuery extends Query {
}
return new DefaultScorerSupplier(scorer);
}
-
- @Override
- public int count(LeafReaderContext context) throws IOException {
- // Signal we can't compute the exact count in sublinear time.
- return -1;
- }
}
private static class RandomApproximationScorer extends Scorer {
diff --git a/lucene/test-framework/src/java/org/apache/lucene/tests/store/CorruptingIndexOutput.java b/lucene/test-framework/src/java/org/apache/lucene/tests/store/CorruptingIndexOutput.java
index 765c7489897..c3c3ebf4313 100644
--- a/lucene/test-framework/src/java/org/apache/lucene/tests/store/CorruptingIndexOutput.java
+++ b/lucene/test-framework/src/java/org/apache/lucene/tests/store/CorruptingIndexOutput.java
@@ -36,6 +36,11 @@ public class CorruptingIndexOutput extends FilterIndexOutput {
this.byteToCorrupt = byteToCorrupt;
}
+ @Override
+ public String getName() {
+ return out.getName();
+ }
+
@Override
public void close() throws IOException {
if (closed == false) {
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 af6fad301cf..8d1a2b9aa20 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
@@ -64,7 +64,6 @@ import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
-import java.lang.reflect.Modifier;
import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
@@ -74,20 +73,17 @@ import java.nio.file.Paths;
import java.text.Collator;
import java.util.ArrayList;
import java.util.Arrays;
-import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
-import java.util.LinkedHashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Random;
import java.util.Set;
-import java.util.StringJoiner;
import java.util.TimeZone;
import java.util.TreeSet;
import java.util.concurrent.Executor;
@@ -3347,154 +3343,4 @@ public abstract class LuceneTestCase extends Assert {
return intraMergeExecutor;
}
}
-
- /**
- * Verifies that the given delegator class overrides all methods that it is expected to delegate.
- *
- * @param delegator the decorating class whose overrides must be verified
- * @see #assertDelegatorOverridesAllRequiredMethods(Class, Set)
- */
- protected static void assertDelegatorOverridesAllRequiredMethods(Class<?> delegator) {
- assertDelegatorOverridesAllRequiredMethods(delegator, Set.of());
- }
-
- /**
- * Verifies that the given delegator class overrides all methods that it is expected to delegate.
- *
- * @param delegator the decorating class whose overrides must be verified
- * @param exclude the methods that should be ignored by the checks
- */
- protected static void assertDelegatorOverridesAllRequiredMethods(
- Class<?> delegator, Set<Method> exclude) {
- Set<String> missingOverrides = new LinkedHashSet<>();
- for (Method m : getMethods(delegator)) {
- if (!exclude.contains(m)
- && m.getDeclaringClass() != delegator
- && requiresDelegatorOverride(m)) {
- missingOverrides.add(methodSignature(m));
- }
- }
- if (!missingOverrides.isEmpty()) {
- fail(
- String.format(
- Locale.US,
- "The decorating class %s must override the following methods: %s",
- delegator.getSimpleName(),
- String.join(", ", missingOverrides)));
- }
- }
-
- /**
- * Returns the effective set of methods visible on the given class, filtering out overridden
- * declarations introduced by the reflection changes in Java 21+.
- *
- * @param clazz the class whose effective methods should be enumerated
- * @return a collection of methods where each signature appears at most once, resolved to the most
- * specific declaring class
- */
- private static Collection<Method> getMethods(Class<?> clazz) {
- Map<MethodKey, Method> methods = new HashMap<>();
- collectDeclaredMethods(clazz, methods);
- return methods.values();
- }
-
- /**
- * Recursively collects declared methods from the class hierarchy into the provided map, keeping
- * only the most specific declaration for each method signature.
- *
- * @param clazz the class being inspected
- * @param methods the map collecting signature-to-method entries
- */
- private static void collectDeclaredMethods(Class<?> clazz, Map<MethodKey, Method> methods) {
-
- for (Class<?> i : clazz.getInterfaces()) {
- collectDeclaredMethods(i, methods);
- }
-
- Class<?> superclass = clazz.getSuperclass();
- if (superclass != null && superclass != Object.class) {
- collectDeclaredMethods(superclass, methods);
- }
-
- for (Method m : clazz.getDeclaredMethods()) {
- MethodKey key = new MethodKey(m);
- Method previous = methods.get(key);
- if (previous != null && previous.getDeclaringClass() == clazz) {
- Class<?> previousReturnType = previous.getReturnType();
- Class<?> newReturnType = m.getReturnType();
- if (previousReturnType.isAssignableFrom(newReturnType)) {
- methods.put(key, m);
- }
- } else {
- methods.put(key, m);
- }
- }
- }
-
- /**
- * Signature key: method name + parameter types. We use a List for parameter types so that record
- * equality works with element-wise comparison.
- */
- private record MethodKey(String name, List<Class<?>> parameterTypes) {
- MethodKey(Method m) {
- this(m.getName(), List.of(m.getParameterTypes()));
- }
- }
-
- private static String methodSignature(Method m) {
- String name =
- String.format(
- Locale.US,
- "%s %s.%s",
- m.getReturnType().getSimpleName(),
- m.getDeclaringClass().getSimpleName(),
- m.getName());
-
- StringJoiner sj = new StringJoiner(", ", name + "(", ")");
- for (Class<?> parameterType : m.getParameterTypes()) {
- sj.add(parameterType.getSimpleName());
- }
- return sj.toString();
- }
-
- /**
- * Determines whether the given method must be overridden by a delegator class.
- *
- * <p>A method is considered required to override if it is:
- *
- * <ul>
- * <li>public,
- * <li>non-static,
- * <li>non-final,
- * <li>not declared on {@link Object},
- * <li>non abstract
- * </ul>
- *
- * @param m the method to inspect
- * @return {@code true} if the delegator must override this method
- */
- private static boolean requiresDelegatorOverride(Method m) {
-
- int modifier = m.getModifiers();
-
- // We want to ignore Objects methods as a base delegator cannot override them correctly anyway.
- return !isObjectMethod(m)
- && Modifier.isPublic(modifier)
- && !Modifier.isStatic(modifier)
- && !Modifier.isFinal(modifier)
- // We keep only the last method implementation, therefore, if it is abstract java will force
- // the implementation to define it.
- && !Modifier.isAbstract(modifier);
- }
-
- private static boolean isObjectMethod(Method m) {
- try {
- Object.class.getMethod(m.getName(), m.getParameterTypes());
- return true;
- } catch (
- @SuppressWarnings("unused")
- NoSuchMethodException ignored) {
- return false;
- }
- }
}