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:30:14 UTC
lucene-solr:branch_6x: LUCENE-7340: MemoryIndex.toString renamed to
toStringDebug; fix NPE (cherry picked from commit 3ca4fea)
Repository: lucene-solr
Updated Branches:
refs/heads/branch_6x 4ff882e4a -> 4a1b78af7
LUCENE-7340: MemoryIndex.toString renamed to toStringDebug; fix NPE
(cherry picked from commit 3ca4fea)
Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/4a1b78af
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/4a1b78af
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/4a1b78af
Branch: refs/heads/branch_6x
Commit: 4a1b78af715a33d1d17aadc09b82003a3d11d157
Parents: 4ff882e
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:30:08 2016 -0400
----------------------------------------------------------------------
lucene/CHANGES.txt | 7 +++++
.../apache/lucene/index/memory/MemoryIndex.java | 27 +++++++++++++++++---
.../lucene/index/memory/TestMemoryIndex.java | 22 ++++++++++++++++
3 files changed, 52 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/4a1b78af/lucene/CHANGES.txt
----------------------------------------------------------------------
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index dcf5a94..e1350be 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -25,6 +25,13 @@ New Features
analyzer for the Ukrainian language (Andriy Rysin via Mike
McCandless)
+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/4a1b78af/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/4a1b78af/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());
+ }
+
}