Buggy code:
if ( de == null ) { throw new IllegalArgumentException ( ( ( "field<seq2seq4repair_space>'" + field ) + "'<seq2seq4repair_space>was<seq2seq4repair_space>indexed<seq2seq4repair_space>without<seq2seq4repair_space>offsets,<seq2seq4repair_space>cannot<seq2seq4repair_space>highlight" ) ) ; } pDoc = de . advance ( doc ) ; } else { pDoc = de . docID ( ) ; if ( pDoc < doc ) { pDoc = de . advance ( doc ) ; } } if ( doc == pDoc ) { weights [ i ] = scorer . weight ( contentLength , de . freq ( ) ) ; de . nextPosition ( ) ; pq . add ( new PostingsHighlighter . OffsetsEnum ( de , i ) ) ; } } pq . add ( new PostingsHighlighter . OffsetsEnum ( PostingsHighlighter . EMPTY , Integer . MAX_VALUE ) ) ; PriorityQueue < Passage > passageQueue = new PriorityQueue < Passage > ( n , new Comparator < Passage > ( ) { @ Override public int compare ( Passage left , Passage right ) { if ( ( left . score ) < ( right . score ) ) { return - 1 ; } else if ( ( left . score ) > ( right . score ) ) { return 1 ; } else { return ( left . startOffset ) - ( right . startOffset ) ; } } } ) ; Passage current = new Passage ( ) ; PostingsHighlighter . OffsetsEnum off ; while ( ( off = pq . poll ( ) ) != null ) { final DocsAndPositionsEnum dp = off . dp ; int start = dp . startOffset ( ) ; if ( start == ( - 1 ) ) { throw new IllegalArgumentException ( ( ( "field<seq2seq4repair_space>'" + field ) + "'<seq2seq4repair_space>was<seq2seq4repair_space>indexed<seq2seq4repair_space>without<seq2seq4repair_space>offsets,<seq2seq4repair_space>cannot<seq2seq4repair_space>highlight" ) ) ; } int end = dp . endOffset ( ) ; assert ( PostingsHighlighter . EMPTY . startOffset ( ) ) == ( Integer . MAX_VALUE ) ; if ( ( start < contentLength ) && ( end > contentLength ) ) { continue ; } if ( start >= ( current . endOffset ) ) { if ( ( current . startOffset ) >= 0 ) { current . score *= scorer . norm ( current . startOffset ) ; if ( ( ( passageQueue . size ( ) ) == n ) && ( ( current . score ) < ( passageQueue . peek ( ) . score ) ) ) { current . reset ( ) ; } else { passageQueue . offer ( current ) ; if ( ( passageQueue . size ( ) ) > n ) { current = passageQueue . poll ( ) ; current . reset ( ) ; } else { current = new Passage ( ) ; } } } if ( start >= contentLength ) { Passage [ ] passages = new Passage [ passageQueue . size ( ) ] ; passageQueue . toArray ( passages ) ; for ( Passage p : passages ) { p . sort ( ) ; } Arrays . sort ( passages , new Comparator < Passage > ( ) { @ Override public int compare ( Passage left , Passage right ) { return ( left . startOffset ) - ( right . startOffset ) ; } } ) ; return passages ; } assert ( BreakIterator . DONE ) < 0 ; current . startOffset = Math . max ( bi . preceding ( ( start + 1 ) ) , 0 ) ; current . endOffset = Math . min ( bi . next ( ) , contentLength ) ; } int tf = 0 ; while ( true ) { tf ++ ; current . addMatch ( start , end , terms [ off . id ] ) ; if ( ( off . pos ) == ( dp . freq ( ) ) ) { break ; } else { ( off . pos ) ++ ; dp . nextPosition ( ) ; start = dp . startOffset ( ) ; end = dp . endOffset ( ) ; } <START_BUG> if ( start >= ( current . endOffset ) ) { <END_BUG> pq . offer ( off ) ; break ; } } current . score += ( weights [ off . id ] ) * ( scorer . tf ( tf , ( ( current . endOffset ) - ( current . startOffset ) ) ) ) ; } assert false ; return null ; } protected Passage [ ] getEmptyHighlight ( String fieldName , BreakIterator bi , int maxPassages ) { } private static class OffsetsEnum implements Comparable < PostingsHighlighter . OffsetsEnum > { DocsAndPositionsEnum dp ; int pos ; int id ; OffsetsEnum ( DocsAndPositionsEnum dp , int id ) throws IOException { } @ Override public int compareTo ( PostingsHighlighter . OffsetsEnum other ) { } } private static final DocsAndPositionsEnum EMPTY = new DocsAndPositionsEnum ( ) { @ Override public int nextPosition ( ) throws IOException { } @ Override public int startOffset ( ) throws IOException { } @ Override public int endOffset ( ) throws IOException { } @ Override public BytesRef getPayload ( ) throws IOException { } @ Override public int freq ( ) throws IOException { } @ Override public int docID ( ) { } @ Override public int nextDoc ( ) throws IOException { } @ Override public int advance ( int target ) throws IOException { } @ Override public long cost ( ) { } } ; private static Query rewrite ( Query original ) throws IOException { } private static class LimitedStoredFieldVisitor extends StoredFieldVisitor { private final String [ ] fields ; private final char [ ] valueSeparators ; private final int maxLength ; private final StringBuilder [ ] builders ; private int currentField = - 1 ; public LimitedStoredFieldVisitor ( String [ ] fields , char [ ] valueSeparators , int maxLength ) { }

Fix:
if ( ( start >= ( current . endOffset ) ) || ( end > contentLength ) ) {