You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by mi...@apache.org on 2016/03/03 12:08:41 UTC

[2/9] lucene-solr git commit: fix NPE, add test case

fix NPE, add test case


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/85dbdb76
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/85dbdb76
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/85dbdb76

Branch: refs/heads/master
Commit: 85dbdb7659498e8a41653b642dc0c9b0e1f69304
Parents: 3c02ab2
Author: Mike McCandless <mi...@apache.org>
Authored: Wed Mar 2 17:59:42 2016 -0500
Committer: Mike McCandless <mi...@apache.org>
Committed: Wed Mar 2 17:59:42 2016 -0500

----------------------------------------------------------------------
 .../org/apache/lucene/index/CheckIndex.java     | 18 +++++++++-------
 .../apache/lucene/index/TestPointValues.java    | 22 ++++++++++++++++++++
 2 files changed, 32 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/85dbdb76/lucene/core/src/java/org/apache/lucene/index/CheckIndex.java
----------------------------------------------------------------------
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 c25531c..db32924 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);
             }
 

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/85dbdb76/lucene/core/src/test/org/apache/lucene/index/TestPointValues.java
----------------------------------------------------------------------
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 7551d3c..506d58c 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();
+  }
 }