lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikemcc...@apache.org
Subject svn commit: r1526529 - in /lucene/dev/branches/branch_4x/lucene: core/src/java/org/apache/lucene/util/PagedBytes.java test-framework/src/java/org/apache/lucene/index/BaseDocValuesFormatTestCase.java
Date Thu, 26 Sep 2013 14:57:54 GMT
Author: mikemccand
Date: Thu Sep 26 14:57:54 2013
New Revision: 1526529

URL: http://svn.apache.org/r1526529
Log:
LUCENE-5218: fix exception when trying to read a 0-byte BinaryDocValues field

Modified:
    lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/util/PagedBytes.java
    lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/index/BaseDocValuesFormatTestCase.java

Modified: lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/util/PagedBytes.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/util/PagedBytes.java?rev=1526529&r1=1526528&r2=1526529&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/util/PagedBytes.java
(original)
+++ lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/util/PagedBytes.java
Thu Sep 26 14:57:54 2013
@@ -86,9 +86,12 @@ public final class PagedBytes {
     public void fillSlice(BytesRef b, long start, int length) {
       assert length >= 0: "length=" + length;
       assert length <= blockSize+1: "length=" + length;
+      b.length = length;
+      if (length == 0) {
+        return;
+      }
       final int index = (int) (start >> blockBits);
       final int offset = (int) (start & blockMask);
-      b.length = length;
       if (blockSize - offset >= length) {
         // Within block
         b.bytes = blocks[index];

Modified: lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/index/BaseDocValuesFormatTestCase.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/index/BaseDocValuesFormatTestCase.java?rev=1526529&r1=1526528&r2=1526529&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/index/BaseDocValuesFormatTestCase.java
(original)
+++ lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/index/BaseDocValuesFormatTestCase.java
Thu Sep 26 14:57:54 2013
@@ -1432,7 +1432,7 @@ public abstract class BaseDocValuesForma
   public void testBinaryFixedLengthVsStoredFields() throws Exception {
     int numIterations = atLeast(1);
     for (int i = 0; i < numIterations; i++) {
-      int fixedLength = _TestUtil.nextInt(random(), 1, 10);
+      int fixedLength = _TestUtil.nextInt(random(), 0, 10);
       doTestBinaryVsStoredFields(fixedLength, fixedLength);
     }
   }
@@ -1440,7 +1440,7 @@ public abstract class BaseDocValuesForma
   public void testBinaryVariableLengthVsStoredFields() throws Exception {
     int numIterations = atLeast(1);
     for (int i = 0; i < numIterations; i++) {
-      doTestBinaryVsStoredFields(1, 10);
+      doTestBinaryVsStoredFields(0, 10);
     }
   }
   
@@ -2958,6 +2958,43 @@ public abstract class BaseDocValuesForma
     dir.close();
   }
 
+  // LUCENE-5218
+  public void testEmptyBinaryValueOnPageSizes() throws Exception {
+    // Test larger and larger power-of-two sized values,
+    // followed by empty string value:
+    for(int i=0;i<20;i++) {
+      if (i > 14 && codecAcceptsHugeBinaryValues("field") == false) {
+        break;
+      }
+      Directory dir = newDirectory();
+      RandomIndexWriter w = new RandomIndexWriter(random(), dir);
+      BytesRef bytes = new BytesRef();
+      bytes.bytes = new byte[1<<i];
+      bytes.length = 1<<i;
+      for(int j=0;j<4;j++) {
+        Document doc = new Document();
+        doc.add(new BinaryDocValuesField("field", bytes));
+        w.addDocument(doc);
+      }
+      Document doc = new Document();
+      doc.add(new StoredField("id", "5"));
+      doc.add(new BinaryDocValuesField("field", new BytesRef()));
+      w.addDocument(doc);
+      IndexReader r = w.getReader();
+      w.close();
+
+      AtomicReader ar = SlowCompositeReaderWrapper.wrap(r);
+      BinaryDocValues values = ar.getBinaryDocValues("field");
+      BytesRef result = new BytesRef();
+      for(int j=0;j<5;j++) {
+        values.get(0, result);
+        assertTrue(result.length == 0 || result.length == 1<<i);
+      }
+      ar.close();
+      dir.close();
+    }
+  }
+
   protected boolean codecAcceptsHugeBinaryValues(String field) {
     return true;
   }



Mime
View raw message