fix NPE, add test case

This commit is contained in:
Mike McCandless 2016-03-02 17:59:42 -05:00
parent 3c02ab2187
commit 85dbdb7659
2 changed files with 32 additions and 8 deletions

View File

@ -1709,17 +1709,19 @@ public final class CheckIndex implements Closeable {
byte[] globalMinPackedValue = values.getMinPackedValue(fieldInfo.name);
long size = values.size(fieldInfo.name);
if (globalMinPackedValue == null && size != 0) {
throw new RuntimeException("getMinPackedValue is null points for field \"" + fieldInfo.name + "\" yet size=" + size);
}
if (globalMinPackedValue.length != packedBytesCount) {
if (globalMinPackedValue == null) {
if (size != 0) {
throw new RuntimeException("getMinPackedValue is null points for field \"" + fieldInfo.name + "\" yet size=" + size);
}
} else if (globalMinPackedValue.length != packedBytesCount) {
throw new RuntimeException("getMinPackedValue for field \"" + fieldInfo.name + "\" return length=" + globalMinPackedValue.length + " array, but should be " + packedBytesCount);
}
byte[] globalMaxPackedValue = values.getMaxPackedValue(fieldInfo.name);
if (globalMaxPackedValue == null && size != 0) {
throw new RuntimeException("getMaxPackedValue is null points for field \"" + fieldInfo.name + "\" yet size=" + size);
}
if (globalMaxPackedValue.length != packedBytesCount) {
if (globalMaxPackedValue == null) {
if (size != 0) {
throw new RuntimeException("getMaxPackedValue is null points for field \"" + fieldInfo.name + "\" yet size=" + size);
}
} else if (globalMaxPackedValue.length != packedBytesCount) {
throw new RuntimeException("getMaxPackedValue for field \"" + fieldInfo.name + "\" return length=" + globalMaxPackedValue.length + " array, but should be " + packedBytesCount);
}

View File

@ -34,6 +34,7 @@ import org.apache.lucene.document.Field;
import org.apache.lucene.document.FloatPoint;
import org.apache.lucene.document.IntPoint;
import org.apache.lucene.document.LongPoint;
import org.apache.lucene.document.StringField;
import org.apache.lucene.index.PointValues.IntersectVisitor;
import org.apache.lucene.index.PointValues.Relation;
import org.apache.lucene.index.PointValues;
@ -540,4 +541,25 @@ public class TestPointValues extends LuceneTestCase {
w.close();
dir.close();
}
public void testDeleteAllPointDocs() throws Exception {
Directory dir = newDirectory();
IndexWriterConfig iwc = newIndexWriterConfig();
IndexWriter w = new IndexWriter(dir, iwc);
Document doc = new Document();
doc.add(new StringField("id", "0", Field.Store.NO));
doc.add(new IntPoint("int", 17));
w.addDocument(doc);
w.addDocument(new Document());
w.commit();
w.deleteDocuments(new Term("id", "0"));
w.forceMerge(1);
DirectoryReader r = w.getReader();
assertEquals(0, r.leaves().get(0).reader().getPointValues().size("int"));
w.close();
r.close();
dir.close();
}
}