mirror of https://github.com/apache/lucene.git
LUCENE-781: fixed NPE in MultiReader.isCurrent() and getVersion()
git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@499152 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
d8979209bc
commit
fb60f574aa
|
@ -332,6 +332,11 @@ Bug fixes
|
|||
life" due to this, just a possible future problem). (Chuck
|
||||
Williams via Mike McCandless)
|
||||
|
||||
33. LUCENE-781: Fixed the NullPointerException in MultiReader.isCurrent()
|
||||
and MultiReader.getVersion(). isCurrent() now returns true only if
|
||||
all its readers are current. getVersion() now throws an
|
||||
UnsupportedOperationException. (Daniel Naber)
|
||||
|
||||
Optimizations
|
||||
|
||||
1. LUCENE-586: TermDocs.skipTo() is now more efficient for
|
||||
|
|
|
@ -262,6 +262,30 @@ public class MultiReader extends IndexReader {
|
|||
}
|
||||
return fieldSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns <code>true</code> if all readers are still up-to-date.
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
public boolean isCurrent() throws IOException {
|
||||
for (int i = 0; i < subReaders.length; i++) {
|
||||
IndexReader reader = subReaders[i];
|
||||
if (!reader.isCurrent())
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Not implemented.
|
||||
* @throws UnsupportedOperationException
|
||||
*/
|
||||
public long getVersion() {
|
||||
throw new UnsupportedOperationException("This method is only implemented in " +
|
||||
"IndexReader, not in MultiReader");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class MultiTermEnum extends TermEnum {
|
||||
|
|
|
@ -18,7 +18,10 @@ package org.apache.lucene.index;
|
|||
*/
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.apache.lucene.analysis.standard.StandardAnalyzer;
|
||||
import org.apache.lucene.document.Document;
|
||||
import org.apache.lucene.document.Field;
|
||||
import org.apache.lucene.store.Directory;
|
||||
import org.apache.lucene.store.RAMDirectory;
|
||||
|
||||
|
@ -102,4 +105,34 @@ public class TestMultiReader extends TestCase {
|
|||
MultiReader reader = new MultiReader(dir, sis, false, readers);
|
||||
assertTrue(reader != null);
|
||||
}
|
||||
|
||||
public void testIsCurrent() throws IOException {
|
||||
RAMDirectory ramDir1=new RAMDirectory();
|
||||
addDoc(ramDir1, "test foo", true);
|
||||
RAMDirectory ramDir2=new RAMDirectory();
|
||||
addDoc(ramDir2, "test blah", true);
|
||||
IndexReader[] readers = new IndexReader[]{IndexReader.open(ramDir1), IndexReader.open(ramDir2)};
|
||||
MultiReader mr = new MultiReader(readers);
|
||||
assertTrue(mr.isCurrent()); // just opened, must be current
|
||||
addDoc(ramDir1, "more text", false);
|
||||
assertFalse(mr.isCurrent()); // has been modified, not current anymore
|
||||
addDoc(ramDir2, "even more text", false);
|
||||
assertFalse(mr.isCurrent()); // has been modified even more, not current anymore
|
||||
try {
|
||||
mr.getVersion();
|
||||
fail();
|
||||
} catch (UnsupportedOperationException e) {
|
||||
// expected exception
|
||||
}
|
||||
mr.close();
|
||||
}
|
||||
|
||||
private void addDoc(RAMDirectory ramDir1, String s, boolean create) throws IOException {
|
||||
IndexWriter iw = new IndexWriter(ramDir1, new StandardAnalyzer(), create);
|
||||
Document doc = new Document();
|
||||
doc.add(new Field("body", s, Field.Store.YES, Field.Index.TOKENIZED));
|
||||
iw.addDocument(doc);
|
||||
iw.close();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue