Details

    • Lucene Fields:
      New, Patch Available

      Description

      While extending the index writer, I discovered that its newestSegment method does not check to see if there are any segments before accessing the segment infos vector. Specifically, if you call the IndexWriter#newestSegment method on a brand-new index which is essentially empty, then it throws an java.lang.ArrayIndexOutOfBoundsException exception.

      The proposed fix is to return null if no segments exist, as shown below:

      — lucene/src/java/org/apache/lucene/index/IndexWriter.java (revision 930788)
      +++ lucene/src/java/org/apache/lucene/index/IndexWriter.java (working copy)
      @@ -4587,7 +4587,7 @@

      // utility routines for tests
      SegmentInfo newestSegment()

      { - return segmentInfos.info(segmentInfos.size()-1); + return segmentInfos.size() > 0 ? segmentInfos.info(segmentInfos.size()-1) : null; }
      1. LUCENE-2365.patch
        2 kB
        Karthick Sankarachary

        Activity

        Hide
        Karthick Sankarachary added a comment -

        The unit test case that expose this issue, along with the proposed patch can be found in LUCENE-2365.patch.

        Show
        Karthick Sankarachary added a comment - The unit test case that expose this issue, along with the proposed patch can be found in LUCENE-2365 .patch.
        Hide
        Michael McCandless added a comment -

        Thanks, patch looks good; I'll commit shortly!

        Show
        Michael McCandless added a comment - Thanks, patch looks good; I'll commit shortly!
        Hide
        Michael McCandless added a comment -

        Thanks Karthick!

        Show
        Michael McCandless added a comment - Thanks Karthick!
        Hide
        Robert Muir added a comment -

        reopening for possible 2.9.4/3.0.3 backport.

        Show
        Robert Muir added a comment - reopening for possible 2.9.4/3.0.3 backport.
        Hide
        Robert Muir added a comment -

        Committed revision 1029013 to 3.0.x
        Committed revision 1029016 to 2.9.x

        Show
        Robert Muir added a comment - Committed revision 1029013 to 3.0.x Committed revision 1029016 to 2.9.x

          People

          • Assignee:
            Michael McCandless
            Reporter:
            Karthick Sankarachary
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development