From 85dbdb7659498e8a41653b642dc0c9b0e1f69304 Mon Sep 17 00:00:00 2001 From: Mike McCandless Date: Wed, 2 Mar 2016 17:59:42 -0500 Subject: [PATCH] fix NPE, add test case --- .../org/apache/lucene/index/CheckIndex.java | 18 ++++++++------- .../apache/lucene/index/TestPointValues.java | 22 +++++++++++++++++++ 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/lucene/core/src/java/org/apache/lucene/index/CheckIndex.java b/lucene/core/src/java/org/apache/lucene/index/CheckIndex.java index c25531c0f55..db3292486a0 100644 --- a/lucene/core/src/java/org/apache/lucene/index/CheckIndex.java +++ b/lucene/core/src/java/org/apache/lucene/index/CheckIndex.java @@ -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); } diff --git a/lucene/core/src/test/org/apache/lucene/index/TestPointValues.java b/lucene/core/src/test/org/apache/lucene/index/TestPointValues.java index 7551d3c3f2d..506d58cedbb 100644 --- a/lucene/core/src/test/org/apache/lucene/index/TestPointValues.java +++ b/lucene/core/src/test/org/apache/lucene/index/TestPointValues.java @@ -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(); + } }