Apache Solr open-source search software
also assert points stats docCount <= maxDoc, and docCount >=0 and size >= 0
Mike McCandless2d5519a0ee74
diff --git a/lucene/core/src/java/org/apache/lucene/index/CheckIndex.java b/lucene/core/src/java/org/apache/lucene/index/CheckIndex.javaindex 012f88ae9dd..1da69c14c5c 100644--- a/lucene/core/src/java/org/apache/lucene/index/CheckIndex.java+++ b/lucene/core/src/java/org/apache/lucene/index/CheckIndex.java@@ -1716,6 +1716,10 @@ public final class CheckIndex implements Closeable {throw new RuntimeException("point values for field \"" + fieldInfo.name + "\" claims to have size=" + size + " points and inconsistent docCount=" + docCount);}+ if (docCount > reader.maxDoc()) {+ throw new RuntimeException("point values for field \"" + fieldInfo.name + "\" claims to have docCount=" + docCount + " but that's greater than maxDoc=" + reader.maxDoc());+ }+if (globalMinPackedValue == null) {if (size != 0) {throw new RuntimeException("getMinPackedValue is null points for field \"" + fieldInfo.name + "\" yet size=" + size);diff --git a/lucene/test-framework/src/java/org/apache/lucene/codecs/asserting/AssertingPointFormat.java b/lucene/test-framework/src/java/org/apache/lucene/codecs/asserting/AssertingPointFormat.javaindex 892eeef6852..07365e02e13 100644--- a/lucene/test-framework/src/java/org/apache/lucene/codecs/asserting/AssertingPointFormat.java+++ b/lucene/test-framework/src/java/org/apache/lucene/codecs/asserting/AssertingPointFormat.java@@ -64,7 +64,7 @@ public final class AssertingPointFormat extends PointFormat {@Overridepublic PointReader fieldsReader(SegmentReadState state) throws IOException {- return new AssertingPointReader(in.fieldsReader(state));+ return new AssertingPointReader(state.segmentInfo.maxDoc(), in.fieldsReader(state));}/** Validates in the 1D case that all points are visited in order, and point values are in bounds of the last cell checked */@@ -146,9 +146,11 @@ public final class AssertingPointFormat extends PointFormat {static class AssertingPointReader extends PointReader {private final PointReader in;+ private final int maxDoc;- AssertingPointReader(PointReader in) {+ AssertingPointReader(int maxDoc, PointReader in) {this.in = in;+ this.maxDoc = maxDoc;// do a few simple checks on initassert toString() != null;assert ramBytesUsed() >= 0;@@ -188,7 +190,7 @@ public final class AssertingPointFormat extends PointFormat {@Overridepublic PointReader getMergeInstance() throws IOException {- return new AssertingPointReader(in.getMergeInstance());+ return new AssertingPointReader(maxDoc, in.getMergeInstance());}@Override@@ -198,35 +200,46 @@ public final class AssertingPointFormat extends PointFormat {@Overridepublic byte[] getMinPackedValue(String fieldName) throws IOException {+ assertStats(fieldName);return in.getMinPackedValue(fieldName);}@Overridepublic byte[] getMaxPackedValue(String fieldName) throws IOException {+ assertStats(fieldName);return in.getMaxPackedValue(fieldName);}@Overridepublic int getNumDimensions(String fieldName) throws IOException {+ assertStats(fieldName);return in.getNumDimensions(fieldName);}@Overridepublic int getBytesPerDimension(String fieldName) throws IOException {+ assertStats(fieldName);return in.getBytesPerDimension(fieldName);}@Overridepublic long size(String fieldName) {- // TODO: what to assert?+ assertStats(fieldName);return in.size(fieldName);}@Overridepublic int getDocCount(String fieldName) {- // TODO: what to assert?+ assertStats(fieldName);return in.getDocCount(fieldName);}++ private void assertStats(String fieldName) {+ assert in.size(fieldName) >= 0;+ assert in.getDocCount(fieldName) >= 0;+ assert in.getDocCount(fieldName) <= in.size(fieldName);+ assert in.getDocCount(fieldName) <= maxDoc;+ }}static class AssertingPointWriter extends PointWriter {