From 0cb96adf12063c1ec2d586d0cec6a209abe9a2dd Mon Sep 17 00:00:00 2001 From: Michael McCandless Date: Fri, 18 Sep 2009 12:33:51 +0000 Subject: [PATCH] LUCENE-1918: fix corner cases (resulting in exceptions) when passing ParallelReader to IndexWriter.addIndexes git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@816602 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES.txt | 7 + .../apache/lucene/index/ParallelReader.java | 7 +- .../lucene/index/TermVectorsWriter.java | 12 +- .../index/TestParallelReaderEmptyIndex.java | 136 ++++++++++++++++++ 4 files changed, 156 insertions(+), 6 deletions(-) create mode 100644 src/test/org/apache/lucene/index/TestParallelReaderEmptyIndex.java diff --git a/CHANGES.txt b/CHANGES.txt index 0e55666f811..9b33bb34b0a 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -559,6 +559,13 @@ Bug fixes OpenBitSet, due to an inefficiency in how the underlying storage is reallocated. (Nadav Har'El via Mike McCandless) + * LUCENE-1918: Fixed cases where a ParallelReader would + generate exceptions on being passed to + IndexWriter.addIndexes(IndexReader[]). First case was when the + ParallelReader was empty. Second case was when the ParallelReader + used to contain documents with TermVectors, but all such documents + have been deleted. (Christian Kohlschütter via Mike McCandless) + New features * LUCENE-1411: Added expert API to open an IndexWriter on a prior diff --git a/src/java/org/apache/lucene/index/ParallelReader.java b/src/java/org/apache/lucene/index/ParallelReader.java index 7c222a589a3..a974c88f3ab 100644 --- a/src/java/org/apache/lucene/index/ParallelReader.java +++ b/src/java/org/apache/lucene/index/ParallelReader.java @@ -472,7 +472,12 @@ public class ParallelReader extends IndexReader { private TermEnum termEnum; public ParallelTermEnum() throws IOException { - field = (String)fieldToReader.firstKey(); + try { + field = (String)fieldToReader.firstKey(); + } catch(NoSuchElementException e) { + // No fields, so keep field == null, termEnum == null + return; + } if (field != null) termEnum = ((IndexReader)fieldToReader.get(field)).terms(); } diff --git a/src/java/org/apache/lucene/index/TermVectorsWriter.java b/src/java/org/apache/lucene/index/TermVectorsWriter.java index 0d5e4fc4378..4c69908877e 100644 --- a/src/java/org/apache/lucene/index/TermVectorsWriter.java +++ b/src/java/org/apache/lucene/index/TermVectorsWriter.java @@ -156,11 +156,13 @@ final class TermVectorsWriter { } // 2nd pass: write field pointers to tvd - long lastFieldPointer = fieldPointers[0]; - for (int i=1; i 1) { + long lastFieldPointer = fieldPointers[0]; + for (int i=1; i