Apache Solr open-source search software
LUCENE-5703: fix safety bug for FC's BINARY too
Robert Muir529edff3ba6e
diff --git a/lucene/misc/src/java/org/apache/lucene/uninverting/FieldCacheImpl.java b/lucene/misc/src/java/org/apache/lucene/uninverting/FieldCacheImpl.javaindex 92772d7d102..6d699a4cb8d 100644--- a/lucene/misc/src/java/org/apache/lucene/uninverting/FieldCacheImpl.java+++ b/lucene/misc/src/java/org/apache/lucene/uninverting/FieldCacheImpl.java@@ -679,26 +679,29 @@ class FieldCacheImpl implements FieldCache {}}- 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 FieldCache {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 {diff --git a/lucene/misc/src/test/org/apache/lucene/uninverting/TestFieldCache.java b/lucene/misc/src/test/org/apache/lucene/uninverting/TestFieldCache.javaindex f58c3d85bfc..b8631734cbe 100644--- a/lucene/misc/src/test/org/apache/lucene/uninverting/TestFieldCache.java+++ b/lucene/misc/src/test/org/apache/lucene/uninverting/TestFieldCache.java@@ -242,7 +242,6 @@ public class TestFieldCache extends LuceneTestCase {// getTermsBinaryDocValues 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;