You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by rm...@apache.org on 2014/06/05 20:07:16 UTC

svn commit: r1600716 - in /lucene/dev/trunk/lucene/misc/src: java/org/apache/lucene/uninverting/FieldCacheImpl.java test/org/apache/lucene/uninverting/TestFieldCache.java

Author: rmuir
Date: Thu Jun  5 18:07:15 2014
New Revision: 1600716

URL: http://svn.apache.org/r1600716
Log:
LUCENE-5703: fix safety bug for FC's BINARY too

Modified:
    lucene/dev/trunk/lucene/misc/src/java/org/apache/lucene/uninverting/FieldCacheImpl.java
    lucene/dev/trunk/lucene/misc/src/test/org/apache/lucene/uninverting/TestFieldCache.java

Modified: lucene/dev/trunk/lucene/misc/src/java/org/apache/lucene/uninverting/FieldCacheImpl.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/misc/src/java/org/apache/lucene/uninverting/FieldCacheImpl.java?rev=1600716&r1=1600715&r2=1600716&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/misc/src/java/org/apache/lucene/uninverting/FieldCacheImpl.java (original)
+++ lucene/dev/trunk/lucene/misc/src/java/org/apache/lucene/uninverting/FieldCacheImpl.java Thu Jun  5 18:07:15 2014
@@ -679,26 +679,29 @@ class FieldCacheImpl implements FieldCac
     }
   }
 
-  private static class BinaryDocValuesImpl extends BinaryDocValues {
+  private static class BinaryDocValuesImpl {
     private final PagedBytes.Reader bytes;
     private final PackedInts.Reader docToOffset;
-    private final BytesRef term;
 
     public BinaryDocValuesImpl(PagedBytes.Reader bytes, PackedInts.Reader docToOffset) {
       this.bytes = bytes;
       this.docToOffset = docToOffset;
-      term = new BytesRef();
     }
-
-    @Override
-    public BytesRef get(int docID) {
-      final int pointer = (int) docToOffset.get(docID);
-      if (pointer == 0) {
-        term.length = 0;
-      } else {
-        bytes.fill(term, pointer);
-      }
-      return term;
+    
+    public BinaryDocValues iterator() {
+      final BytesRef term = new BytesRef();
+      return new BinaryDocValues() {
+        @Override
+        public BytesRef get(int docID) {
+          final int pointer = (int) docToOffset.get(docID);
+          if (pointer == 0) {
+            term.length = 0;
+          } else {
+            bytes.fill(term, pointer);
+          }
+          return term;
+        }   
+      };
     }
   }
 
@@ -729,7 +732,8 @@ class FieldCacheImpl implements FieldCac
       return DocValues.emptyBinary();
     }
 
-    return (BinaryDocValues) caches.get(BinaryDocValues.class).get(reader, new CacheKey(field, acceptableOverheadRatio), setDocsWithField);
+    BinaryDocValuesImpl impl = (BinaryDocValuesImpl) caches.get(BinaryDocValues.class).get(reader, new CacheKey(field, acceptableOverheadRatio), setDocsWithField);
+    return impl.iterator();
   }
 
   static final class BinaryDocValuesCache extends Cache {

Modified: lucene/dev/trunk/lucene/misc/src/test/org/apache/lucene/uninverting/TestFieldCache.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/misc/src/test/org/apache/lucene/uninverting/TestFieldCache.java?rev=1600716&r1=1600715&r2=1600716&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/misc/src/test/org/apache/lucene/uninverting/TestFieldCache.java (original)
+++ lucene/dev/trunk/lucene/misc/src/test/org/apache/lucene/uninverting/TestFieldCache.java Thu Jun  5 18:07:15 2014
@@ -242,7 +242,6 @@ public class TestFieldCache extends Luce
 
     // getTerms
     BinaryDocValues terms = cache.getTerms(reader, "theRandomUnicodeString", true);
-    assertSame("Second request to cache return same array", terms, cache.getTerms(reader, "theRandomUnicodeString", true));
     Bits bits = cache.getDocsWithField(reader, "theRandomUnicodeString");
     for (int i = 0; i < NUM_DOCS; i++) {
       final String s;