Buggy code:
final class SegmentMerger { static final byte [ ] NORMS_HEADER = new byte [ ] { 'N' , 'R' , 'M' , - 1 } ; private Directory directory ; private String segment ; private int termIndexInterval = IndexWriter . DEFAULT_TERM_INDEX_INTERVAL ; private Vector readers = new Vector ( ) ; private FieldInfos fieldInfos ; SegmentMerger ( Directory dir , String name ) { } SegmentMerger ( IndexWriter writer , String name ) { } final void add ( IndexReader reader ) { } final IndexReader segmentReader ( int i ) { } final int merge ( ) throws IOException { } final void closeReaders ( ) throws IOException { } final Vector createCompoundFile ( String fileName ) throws IOException { } private void addIndexed ( IndexReader reader , FieldInfos fieldInfos , Collection names , boolean storeTermVectors , boolean storePositionWithTermVector , boolean storeOffsetWithTermVector ) throws IOException { } private final int mergeFields ( ) throws IOException { } private final void mergeVectors ( ) throws IOException { } private IndexOutput freqOutput = null ; private IndexOutput proxOutput = null ; private TermInfosWriter termInfosWriter = null ; private int skipInterval ; private SegmentMergeQueue queue = null ; private final void mergeTerms ( ) throws IOException { } private final void mergeTermInfos ( ) throws IOException { } private final TermInfo termInfo = new TermInfo ( ) ; private final void mergeTermInfo ( SegmentMergeInfo [ ] smis , int n ) throws IOException { } private final int appendPostings ( SegmentMergeInfo [ ] smis , int n ) throws IOException { int lastDoc = 0 ; int df = 0 ; resetSkip ( ) ; for ( int i = 0 ; i < n ; i ++ ) { SegmentMergeInfo smi = smis [ i ] ; TermPositions postings = smi . getPositions ( ) ; int base = smi . base ; int [ ] docMap = smi . getDocMap ( ) ; postings . seek ( smi . termEnum ) ; while ( postings . next ( ) ) { int doc = postings . doc ( ) ; if ( docMap != null ) doc = docMap [ doc ] ; doc += base ; <START_BUG> if ( ( lastDoc != 0 ) && ( doc <= lastDoc ) ) <END_BUG> throw new IllegalStateException ( ( ( ( ( "docs<seq2seq4repair_space>out<seq2seq4repair_space>of<seq2seq4repair_space>order<seq2seq4repair_space>(" + doc ) + "<seq2seq4repair_space><=<seq2seq4repair_space>" ) + lastDoc ) + "<seq2seq4repair_space>)" ) ) ; df ++ ; if ( ( df % ( skipInterval ) ) == 0 ) { bufferSkip ( lastDoc ) ; } int docCode = ( doc - lastDoc ) << 1 ; lastDoc = doc ; int freq = postings . freq ( ) ; if ( freq == 1 ) { freqOutput . writeVInt ( ( docCode | 1 ) ) ; } else { freqOutput . writeVInt ( docCode ) ; freqOutput . writeVInt ( freq ) ; } int lastPosition = 0 ; for ( int j = 0 ; j < freq ; j ++ ) { int position = postings . nextPosition ( ) ; proxOutput . writeVInt ( ( position - lastPosition ) ) ; lastPosition = position ; } } } return df ; } private RAMOutputStream skipBuffer = new RAMOutputStream ( ) ; private int lastSkipDoc ; private long lastSkipFreqPointer ; private long lastSkipProxPointer ; private void resetSkip ( ) { } private void bufferSkip ( int doc ) throws IOException { } private long writeSkip ( ) throws IOException { } private void mergeNorms ( ) throws IOException { } }

Fix:
if ( ( doc < 0 ) || ( ( df > 0 ) && ( doc <= lastDoc ) ) )