Buggy code:
if ( skip ) { CheckIndex . out . println ( "\nERROR:<seq2seq4repair_space>this<seq2seq4repair_space>index<seq2seq4repair_space>appears<seq2seq4repair_space>to<seq2seq4repair_space>be<seq2seq4repair_space>created<seq2seq4repair_space>by<seq2seq4repair_space>a<seq2seq4repair_space>newer<seq2seq4repair_space>version<seq2seq4repair_space>of<seq2seq4repair_space>Lucene<seq2seq4repair_space>than<seq2seq4repair_space>this<seq2seq4repair_space>tool<seq2seq4repair_space>was<seq2seq4repair_space>compiled<seq2seq4repair_space>on;<seq2seq4repair_space>please<seq2seq4repair_space>re-compile<seq2seq4repair_space>this<seq2seq4repair_space>tool<seq2seq4repair_space>on<seq2seq4repair_space>the<seq2seq4repair_space>matching<seq2seq4repair_space>version<seq2seq4repair_space>of<seq2seq4repair_space>Lucene;<seq2seq4repair_space>exiting" ) ; return false ; } SegmentInfos newSIS = ( ( SegmentInfos ) ( sis . clone ( ) ) ) ; newSIS . clear ( ) ; boolean changed = false ; int totLoseDocCount = 0 ; int numBadSegments = 0 ; for ( int i = 0 ; i < numSegments ; i ++ ) { final SegmentInfo info = sis . info ( i ) ; if ( ( onlySegments != null ) && ( ! ( onlySegments . contains ( info . name ) ) ) ) continue ; CheckIndex . out . println ( ( ( ( ( ( ( ( "<seq2seq4repair_space>" + ( 1 + i ) ) + "<seq2seq4repair_space>of<seq2seq4repair_space>" ) + numSegments ) + ":<seq2seq4repair_space>name=" ) + ( info . name ) ) + "<seq2seq4repair_space>docCount=" ) + ( info . docCount ) ) ) ; int toLoseDocCount = info . docCount ; SegmentReader reader = null ; try { CheckIndex . out . println ( ( "<seq2seq4repair_space>compound=" + ( info . getUseCompoundFile ( ) ) ) ) ; CheckIndex . out . println ( ( "<seq2seq4repair_space>numFiles=" + ( info . files ( ) . size ( ) ) ) ) ; CheckIndex . out . println ( ( "<seq2seq4repair_space>size<seq2seq4repair_space>(MB)=" + ( nf . format ( ( ( info . sizeInBytes ( ) ) // ( 1024.0 * 1024.0 ) ) ) ) ) ) ; final int docStoreOffset = info . getDocStoreOffset ( ) ; if ( docStoreOffset != ( - 1 ) ) { CheckIndex . out . println ( ( "<seq2seq4repair_space>docStoreOffset=" + docStoreOffset ) ) ; CheckIndex . out . println ( ( "<seq2seq4repair_space>docStoreSegment=" + ( info . getDocStoreSegment ( ) ) ) ) ; CheckIndex . out . println ( ( "<seq2seq4repair_space>docStoreIsCompoundFile=" + ( info . getDocStoreIsCompoundFile ( ) ) ) ) ; } final String delFileName = info . getDelFileName ( ) ; if ( delFileName == null ) CheckIndex . out . println ( "<seq2seq4repair_space>no<seq2seq4repair_space>deletions" ) ; else CheckIndex . out . println ( ( ( "<seq2seq4repair_space>has<seq2seq4repair_space>deletions<seq2seq4repair_space>[delFileName=" + delFileName ) + "]" ) ) ; CheckIndex . out . print ( "<seq2seq4repair_space>test:<seq2seq4repair_space>open<seq2seq4repair_space>reader........." ) ; reader = SegmentReader . get ( info ) ; final int numDocs = reader . numDocs ( ) ; toLoseDocCount = numDocs ; if ( reader . hasDeletions ( ) ) CheckIndex . out . println ( ( ( "OK<seq2seq4repair_space>[" + ( ( info . docCount ) - numDocs ) ) + "<seq2seq4repair_space>deleted<seq2seq4repair_space>docs]" ) ) ; else CheckIndex . out . println ( "OK" ) ; CheckIndex . out . print ( "<seq2seq4repair_space>test:<seq2seq4repair_space>fields,<seq2seq4repair_space>norms......." ) ; Collection fieldNames = reader . getFieldNames ( ALL ) ; Iterator it = fieldNames . iterator ( ) ; while ( it . hasNext ( ) ) { final String fieldName = ( ( String ) ( it . next ( ) ) ) ; byte [ ] b = reader . norms ( fieldName ) ; if ( ( b . length ) != ( info . docCount ) ) throw new RuntimeException ( ( ( ( ( ( "norms<seq2seq4repair_space>for<seq2seq4repair_space>field<seq2seq4repair_space>\"" + fieldName ) + "\"<seq2seq4repair_space>is<seq2seq4repair_space>length<seq2seq4repair_space>" ) + ( b . length ) ) + "<seq2seq4repair_space>!=<seq2seq4repair_space>maxDoc<seq2seq4repair_space>" ) + ( info . docCount ) ) ) ; } CheckIndex . out . println ( ( ( "OK<seq2seq4repair_space>[" + ( fieldNames . size ( ) ) ) + "<seq2seq4repair_space>fields]" ) ) ; CheckIndex . out . print ( "<seq2seq4repair_space>test:<seq2seq4repair_space>terms,<seq2seq4repair_space>freq,<seq2seq4repair_space>prox..." ) ; final TermEnum termEnum = reader . terms ( ) ; final TermPositions termPositions = reader . termPositions ( ) ; final CheckIndex . MySegmentTermDocs myTermDocs = new CheckIndex . MySegmentTermDocs ( reader ) ; long termCount = 0 ; long totFreq = 0 ; long totPos = 0 ; while ( termEnum . next ( ) ) { termCount ++ ; final Term term = termEnum . term ( ) ; final int docFreq = termEnum . docFreq ( ) ; termPositions . seek ( term ) ; int lastDoc = - 1 ; int freq0 = 0 ; totFreq += docFreq ; while ( termPositions . next ( ) ) { freq0 ++ ; final int doc = termPositions . doc ( ) ; final int freq = termPositions . freq ( ) ; if ( doc <= lastDoc ) throw new RuntimeException ( ( ( ( ( ( "term<seq2seq4repair_space>" + term ) + ":<seq2seq4repair_space>doc<seq2seq4repair_space>" ) + doc ) + "<seq2seq4repair_space><<seq2seq4repair_space>lastDoc<seq2seq4repair_space>" ) + lastDoc ) ) ; lastDoc = doc ; if ( freq <= 0 ) throw new RuntimeException ( ( ( ( ( ( ( "term<seq2seq4repair_space>" + term ) + ":<seq2seq4repair_space>doc<seq2seq4repair_space>" ) + doc ) + ":<seq2seq4repair_space>freq<seq2seq4repair_space>" ) + freq ) + "<seq2seq4repair_space>is<seq2seq4repair_space>out<seq2seq4repair_space>of<seq2seq4repair_space>bounds" ) ) ; int lastPos = - 1 ; totPos += freq ; for ( int j = 0 ; j < freq ; j ++ ) { final int pos = termPositions . nextPosition ( ) ; if ( pos < 0 ) throw new RuntimeException ( ( ( ( ( ( ( "term<seq2seq4repair_space>" + term ) + ":<seq2seq4repair_space>doc<seq2seq4repair_space>" ) + doc ) + ":<seq2seq4repair_space>pos<seq2seq4repair_space>" ) + pos ) + "<seq2seq4repair_space>is<seq2seq4repair_space>out<seq2seq4repair_space>of<seq2seq4repair_space>bounds" ) ) ; <START_BUG> if ( pos <= lastPos ) <END_BUG>

Fix:
if ( pos < lastPos )