Apache Solr open-source search software
LUCENE-3183: fix corner case seeking to Term(, )
Michael McCandless3ad6ba55d521
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txtindex 1b84eb4b5d2..eef81536a9f 100644--- a/lucene/CHANGES.txt+++ b/lucene/CHANGES.txt@@ -468,6 +468,11 @@ Bug fixes* LUCENE-3102: CachingCollector.replay was failing to call setScorerper-segment (Martijn van Groningen via Mike McCandless)+* LUCENE-3183: Fix rare corner case where seeking to empty term+ (field="", term="") with terms index interval 1 could hit+ ArrayIndexOutOfBoundsException (selckin, Robert Muir, Mike+ McCandless)+New Features* LUCENE-3140: Added experimental FST implementation to Lucene.diff --git a/lucene/src/java/org/apache/lucene/index/codecs/preflex/SegmentTermEnum.java b/lucene/src/java/org/apache/lucene/index/codecs/preflex/SegmentTermEnum.javaindex fb7c8ceec46..6c6681d6a1d 100644--- a/lucene/src/java/org/apache/lucene/index/codecs/preflex/SegmentTermEnum.java+++ b/lucene/src/java/org/apache/lucene/index/codecs/preflex/SegmentTermEnum.java@@ -153,8 +153,12 @@ public final class SegmentTermEnum implements Cloneable {return true;}- /** Optimized scan, without allocating new terms.- * Return number of invocations to next(). */+ /* Optimized scan, without allocating new terms.+ * Return number of invocations to next().+ *+ * NOTE: LUCENE-3183: if you pass Term("", "") here then this+ * will incorrectly return before positioning the enum,+ * and position will be -1; caller must detect this. */final int scanTo(Term term) throws IOException {scanBuffer.set(term);int count = 0;diff --git a/lucene/src/java/org/apache/lucene/index/codecs/preflex/TermInfosReader.java b/lucene/src/java/org/apache/lucene/index/codecs/preflex/TermInfosReader.javaindex c5fd09b7741..8178bd33cf6 100644--- a/lucene/src/java/org/apache/lucene/index/codecs/preflex/TermInfosReader.java+++ b/lucene/src/java/org/apache/lucene/index/codecs/preflex/TermInfosReader.java@@ -57,6 +57,7 @@ public final class TermInfosReader {final long termOrd;public TermInfoAndOrd(TermInfo ti, long termOrd) {super(ti);+ assert termOrd >= 0;this.termOrd = termOrd;}}@@ -306,7 +307,13 @@ public final class TermInfosReader {ti = enumerator.termInfo;if (tiOrd == null) {if (useCache) {- termsCache.put(new CloneableTerm(term), new TermInfoAndOrd(ti, enumerator.position));+ // LUCENE-3183: it's possible, if term is Term("",+ // ""), for the STE to be incorrectly un-positioned+ // after scan-to; work around this by not caching in+ // this case:+ if (enumerator.position >= 0) {+ termsCache.put(new CloneableTerm(term), new TermInfoAndOrd(ti, enumerator.position));+ }}} else {assert sameTermInfo(ti, tiOrd, enumerator);diff --git a/lucene/src/test/org/apache/lucene/index/TestIndexWriter.java b/lucene/src/test/org/apache/lucene/index/TestIndexWriter.javaindex 536a7749a22..ecceb81e2fa 100644--- a/lucene/src/test/org/apache/lucene/index/TestIndexWriter.java+++ b/lucene/src/test/org/apache/lucene/index/TestIndexWriter.java@@ -73,6 +73,7 @@ import org.apache.lucene.util.LuceneTestCase;import org.apache.lucene.util.ThreadInterruptedException;import org.apache.lucene.util.UnicodeUtil;import org.apache.lucene.util._TestUtil;+import org.apache.lucene.index.codecs.preflexrw.PreFlexRWCodec;public class TestIndexWriter extends LuceneTestCase {@@ -1763,4 +1764,18 @@ public class TestIndexWriter extends LuceneTestCase {reader.close();dir.close();}++ // LUCENE-3183+ public void testEmptyFieldNameTIIOne() throws IOException {+ Directory dir = newDirectory();+ IndexWriterConfig iwc = newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random));+ iwc.setTermIndexInterval(1);+ iwc.setReaderTermsIndexDivisor(1);+ IndexWriter writer = new IndexWriter(dir, iwc);+ Document doc = new Document();+ doc.add(newField("", "a b c", Field.Store.NO, Field.Index.ANALYZED));+ writer.addDocument(doc);+ writer.close();+ dir.close();+ }}