Uploaded image for project: 'Lucene - Core'
  1. Lucene - Core
  2. LUCENE-1054

TermDocs.skipTo fails with an ArrayOutOfBoundsException from BitVector

    XMLWordPrintableJSON

    Details

    • Lucene Fields:
      New

      Description

      After a number of calls to TermDocs.skipTo, the following exception is thrown

      java.lang.ArrayIndexOutOfBoundsException: Array index out of range: 101306
      at org.apache.lucene.util.BitVector.get(BitVector.java:72)
      at org.apache.lucene.index.SegmentTermDocs.next(SegmentTermDocs.java:118)
      at org.apache.lucene.index.SegmentTermDocs.skipTo(SegmentTermDocs.java:176)
      at org.apache.lucene.index.MultiTermDocs.skipTo(MultiReader.java:413)

      This error only occurs in 2.2 works okay in 2.1 and in 2.2 if the index is built using 2.1. The following demonstrates the error. The document being skipTo is not greater than the number of documents in the index.

      import java.io.File;
      import java.io.IOException;
      import java.util.Random;

      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.index.CorruptIndexException;
      import org.apache.lucene.index.IndexReader;
      import org.apache.lucene.index.IndexWriter;
      import org.apache.lucene.index.MultiReader;
      import org.apache.lucene.index.Term;
      import org.apache.lucene.index.TermDocs; import org.apache.lucene.store.FSDirectory;
      import org.apache.lucene.store.LockObtainFailedException;

      public class Test4 {

      /**

      • @param args
      • @throws IOException
      • @throws LockObtainFailedException
      • @throws CorruptIndexException
        */
        public static void main(String[] args) throws Exception {
        Random rand = new Random(0);
        FSDirectory[] dirs = new FSDirectory[10];
        boolean build = false;
        for (int i = 0; i < dirs.length; i++) {
        dirs[i] = FSDirectory.getDirectory("c:" + File.separator + "temp"
        + File.separator + "lucenetest" + File.separator
        + Integer.toString);
        if (!IndexReader.indexExists(dirs[i]))
        Unknown macro: { if (!build) { System.out.println("Building Test Index Start"); } build = true; System.out.println("Building Index}

        IndexReader reader = IndexReader.open(dirs[i]);
        for (int j = 0; j < 1000; j++)

        { reader.deleteDocument(rand.nextInt(reader.maxDoc())); }

        reader.close();
        }
        if (build)

        { System.out.println("Building Test Index Complete"); }

        System.out.println("Test Start");
        IndexReader[] readers = new IndexReader[dirs.length];
        for (int i = 0; i < dirs.length; i++)

        { readers[i] = IndexReader.open(dirs[i]); }

        IndexReader reader = new MultiReader(readers);
        TermDocs docs = reader.termDocs();
        for (int i = 0; i < 100; i++) {
        for (int j = 0; j < 1000; j++)

        Unknown macro: { try { test(reader, docs, Integer.toString(i), Integer.toString(j)); } catch (Exception e) { System.err.println("maxdoc=" + reader.maxDoc()); System.err.println("Test Failed at i=" + i + " j=" + j); throw e; } }

        }
        docs.close();
        reader.close();
        System.out.println("Test Complete");
        }

      private static void test(IndexReader reader, TermDocs docs, String i,
      String j) throws Exception {
      docs.seek(new Term("i", i));
      while (docs.next())
      ;
      docs.seek(new Term("j", j));
      while (docs.next())
      ;
      docs.seek(new Term("i", i));
      if (docs.next()) {
      int doc = docs.doc();
      try {
      while (docs.skipTo(doc + 1000))

      { doc = docs.doc(); }
      } catch (Exception e) { System.err.println("doc=" + (doc + 1000) + ": deleted=" + reader.isDeleted(doc + 1000)); throw e; }
      }
      docs.seek(new Term("j", j));
      if (docs.next()) {
      int doc = docs.doc();
      try {
      while (docs.skipTo(doc + 1000)) { doc = docs.doc(); }

      } catch (Exception e)

      { System.err.println("doc=" + doc); throw e; }

      }
      }

      }

        Attachments

        1. Test4.java
          6 kB
          michael streeton
        2. TestSkipTo.java
          6 kB
          Michael McCandless

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              mikestreeton michael streeton
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: