You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ds...@apache.org on 2016/07/06 15:24:13 UTC

lucene-solr:master: LUCENE-7340: MemoryIndex.toString renamed to toStringDebug; fix NPE

Repository: lucene-solr
Updated Branches:
  refs/heads/master 503da1fcb -> 3ca4fea57


LUCENE-7340: MemoryIndex.toString renamed to toStringDebug; fix NPE


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

Branch: refs/heads/master
Commit: 3ca4fea5786430130f25d180440f765e96ac9c74
Parents: 503da1f
Author: David Smiley <ds...@apache.org>
Authored: Wed Jul 6 11:24:03 2016 -0400
Committer: David Smiley <ds...@apache.org>
Committed: Wed Jul 6 11:24:03 2016 -0400

----------------------------------------------------------------------
 lucene/CHANGES.txt                              |  3 +++
 .../apache/lucene/index/memory/MemoryIndex.java | 27 +++++++++++++++++---
 .../lucene/index/memory/TestMemoryIndex.java    | 22 ++++++++++++++++
 3 files changed, 48 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/3ca4fea5/lucene/CHANGES.txt
----------------------------------------------------------------------
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 9f634a5..24d9f65 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -42,6 +42,9 @@ Bug Fixes
 
 * LUCENE-6662: Fixed potential resource leaks. (Rishabh Patel via Adrien Grand)
 
+* LUCENE-7340: MemoryIndex.toString() could throw NPE; fixed. Renamed to toStringDebug().
+  (Daniel Collins, David Smiley)
+
 Improvements
 
 * LUCENE-7323: Compound file writing now verifies the incoming

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/3ca4fea5/lucene/memory/src/java/org/apache/lucene/index/memory/MemoryIndex.java
----------------------------------------------------------------------
diff --git a/lucene/memory/src/java/org/apache/lucene/index/memory/MemoryIndex.java b/lucene/memory/src/java/org/apache/lucene/index/memory/MemoryIndex.java
index cde20e5..cdd53ed 100644
--- a/lucene/memory/src/java/org/apache/lucene/index/memory/MemoryIndex.java
+++ b/lucene/memory/src/java/org/apache/lucene/index/memory/MemoryIndex.java
@@ -43,10 +43,21 @@ import org.apache.lucene.search.SimpleCollector;
 import org.apache.lucene.search.Sort;
 import org.apache.lucene.search.similarities.Similarity;
 import org.apache.lucene.store.RAMDirectory;
-import org.apache.lucene.util.*;
+import org.apache.lucene.util.ArrayUtil;
+import org.apache.lucene.util.Bits;
+import org.apache.lucene.util.ByteBlockPool;
+import org.apache.lucene.util.BytesRef;
+import org.apache.lucene.util.BytesRefArray;
+import org.apache.lucene.util.BytesRefBuilder;
+import org.apache.lucene.util.BytesRefHash;
 import org.apache.lucene.util.BytesRefHash.DirectBytesStartArray;
+import org.apache.lucene.util.Counter;
+import org.apache.lucene.util.IntBlockPool;
 import org.apache.lucene.util.IntBlockPool.SliceReader;
 import org.apache.lucene.util.IntBlockPool.SliceWriter;
+import org.apache.lucene.util.RecyclingByteBlockAllocator;
+import org.apache.lucene.util.RecyclingIntBlockAllocator;
+import org.apache.lucene.util.StringHelper;
 
 /**
  * High-performance single-document main memory Apache Lucene fulltext search index. 
@@ -746,13 +757,14 @@ public class MemoryIndex {
    * Returns a String representation of the index data for debugging purposes.
    * 
    * @return the string representation
+   * @lucene.experimental
    */
-  @Override
-  public String toString() {
+  public String toStringDebug() {
     StringBuilder result = new StringBuilder(256);
     int sumPositions = 0;
     int sumTerms = 0;
     final BytesRef spare = new BytesRef();
+    final BytesRefBuilder payloadBuilder = storePayloads ? new BytesRefBuilder() : null;
     for (Map.Entry<String, Info> entry : fields.entrySet()) {
       String fieldName = entry.getKey();
       Info info = entry.getValue();
@@ -778,9 +790,16 @@ public class MemoryIndex {
               result.append(", ");
             }
           }
+          if (storePayloads) {
+            int payloadIndex = postingsReader.readInt();
+            if (payloadIndex != -1) {
+                result.append(", " + payloadsBytesRefs.get(payloadBuilder, payloadIndex));
+            }
+          }
           result.append(")");
+
           if (!postingsReader.endOfSlice()) {
-            result.append(",");
+            result.append(", ");
           }
 
         }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/3ca4fea5/lucene/memory/src/test/org/apache/lucene/index/memory/TestMemoryIndex.java
----------------------------------------------------------------------
diff --git a/lucene/memory/src/test/org/apache/lucene/index/memory/TestMemoryIndex.java b/lucene/memory/src/test/org/apache/lucene/index/memory/TestMemoryIndex.java
index 5751457..2f95a4e 100644
--- a/lucene/memory/src/test/org/apache/lucene/index/memory/TestMemoryIndex.java
+++ b/lucene/memory/src/test/org/apache/lucene/index/memory/TestMemoryIndex.java
@@ -464,4 +464,26 @@ public class TestMemoryIndex extends LuceneTestCase {
     assertEquals("term", leafReader.getBinaryDocValues("field").get(0).utf8ToString());
   }
 
+  public void testToStringDebug() {
+    MemoryIndex mi = new MemoryIndex(true, true);
+    Analyzer analyzer = new MockPayloadAnalyzer();
+
+    mi.addField("analyzedField", "aa bb aa", analyzer);
+
+    FieldType type = new FieldType();
+    type.setDimensions(1, 4);
+    type.setDocValuesType(DocValuesType.BINARY);
+    type.freeze();
+    mi.addField(new BinaryPoint("pointAndDvField", "term".getBytes(StandardCharsets.UTF_8), type), analyzer);
+
+    assertEquals("analyzedField:\n" +
+        "\t'[61 61]':2: [(0, 0, 2, [70 6f 73 3a 20 30]), (1, 6, 8, [70 6f 73 3a 20 32])]\n" +
+        "\t'[62 62]':1: [(1, 3, 5, [70 6f 73 3a 20 31])]\n" +
+        "\tterms=2, positions=3\n" +
+        "pointAndDvField:\n" +
+        "\tterms=0, positions=0\n" +
+        "\n" +
+        "fields=2, terms=2, positions=3", mi.toStringDebug());
+  }
+
 }