if MultiReader is constructed from array of subreaders (using publis constructor) then calling isCurrent() method will throw NullPointerException.

Testcase is attached below:
//-begin -----TestMultiReaderIsCurrent.java ----------
package org.apache.lucene.index;

import java.io.IOException;

import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.document.Field.Index;
import org.apache.lucene.document.Field.Store;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.RAMDirectory;

import junit.framework.TestCase;

public class TestMultiReaderIsCurrent extends TestCase {

 private Directory dir1 = new RAMDirectory();

 private Directory dir2 = new RAMDirectory();

 public void testIsCurrent() throws IOException {
   addDocument(dir1, "test1", true);
   addDocument(dir2, "test2", true);

   IndexReader ir1 = IndexReader.open(dir1);
   IndexReader ir2 = IndexReader.open(dir2);

   IndexReader mr = new MultiReader(new IndexReader[] {ir1, ir2});

   assertTrue("should be true", ir1.isCurrent());
   assertTrue("should be true", ir2.isCurrent());

   try {
     assertTrue("should be true", mr.isCurrent());
   } catch (RuntimeException e) {
     fail("no exception should be thrown: " + e.toString());
   }

   addDocument(dir1, "test3", false);

   assertFalse("should be false", ir1.isCurrent());
   assertTrue("should be true", ir2.isCurrent());

   try {
     assertFalse("should false", mr.isCurrent());
   } catch (RuntimeException e) {
     fail("no exception should be thrown: " + e.toString());
   }
 }

private void addDocument(Directory dir12, String string, boolean create) throws IOException {
   IndexWriter iw = new IndexWriter(dir12, new StandardAnalyzer(), create);
   Document document = new Document();
   document.add(new Field("data", string, Store.YES, Index.TOKENIZED));
   iw.addDocument(document);
   iw.close();
 }

}
//-end -----TestMultiReaderIsCurrent.java ----------

--
regards,
Volodymyr Bychkoviak

Reply via email to