Buggy code:
, new int [ ] { next_op , next_op , skip_op , skip_op } , new int [ ] { skip_op , skip_op , skip_op , next_op , next_op } } ; for ( int k = 0 ; k < ( orders . length ) ; k ++ ) { final int [ ] order = orders [ k ] ; final int [ ] opidx = new int [ ] { 0 } ; final int [ ] lastDoc = new int [ ] { - 1 } ; final float maxDiff = 1.0E-5F ; final IndexReader [ ] lastReader = new IndexReader [ ] { null } ; s . search ( q , new Collector ( ) { private Scorer sc ; private IndexReader reader ; private Scorer scorer ; @ Override public void setScorer ( Scorer scorer ) throws IOException { this . sc = scorer ; } @ Override public void collect ( int doc ) throws IOException { float score = sc . score ( ) ; lastDoc [ 0 ] = doc ; try { if ( ( scorer ) == null ) { Weight w = q . weight ( s ) ; scorer = w . scorer ( reader , true , false ) ; } int op = order [ ( ( ( opidx [ 0 ] ) ++ ) % ( order . length ) ) ] ; boolean more = ( op == skip_op ) ? ( scorer . advance ( ( ( scorer . docID ( ) ) + 1 ) ) ) != ( DocIdSetIterator . NO_MORE_DOCS ) : ( scorer . nextDoc ( ) ) != ( DocIdSetIterator . NO_MORE_DOCS ) ; int scorerDoc = scorer . docID ( ) ; float scorerScore = scorer . score ( ) ; float scorerScore2 = scorer . score ( ) ; float scoreDiff = Math . abs ( ( score - scorerScore ) ) ; float scorerDiff = Math . abs ( ( scorerScore2 - scorerScore ) ) ; if ( ( ( ( ! more ) || ( doc != scorerDoc ) ) || ( scoreDiff > maxDiff ) ) || ( scorerDiff > maxDiff ) ) { StringBuilder sbord = new StringBuilder ( ) ; for ( int i = 0 ; i < ( order . length ) ; i ++ ) sbord . append ( ( ( order [ i ] ) == skip_op ? "<seq2seq4repair_space>skip()" : "<seq2seq4repair_space>next()" ) ) ; throw new RuntimeException ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( "ERROR<seq2seq4repair_space>matching<seq2seq4repair_space>docs:" + "\n\t" ) + ( doc != scorerDoc ? "--><seq2seq4repair_space>" : "" ) ) + "doc=" ) + doc ) + ",<seq2seq4repair_space>scorerDoc=" ) + scorerDoc ) + "\n\t" ) + ( ! more ? "--><seq2seq4repair_space>" : "" ) ) + "tscorer.more=" ) + more ) + "\n\t" ) + ( scoreDiff > maxDiff ? "--><seq2seq4repair_space>" : "" ) ) + "scorerScore=" ) + scorerScore ) + "<seq2seq4repair_space>scoreDiff=" ) + scoreDiff ) + "<seq2seq4repair_space>maxDiff=" ) + maxDiff ) + "\n\t" ) + ( scorerDiff > maxDiff ? "--><seq2seq4repair_space>" : "" ) ) + "scorerScore2=" ) + scorerScore2 ) + "<seq2seq4repair_space>scorerDiff=" ) + scorerDiff ) + "\n\thitCollector.doc=" ) + doc ) + "<seq2seq4repair_space>score=" ) + score ) + "\n\t<seq2seq4repair_space>Scorer=" ) + ( scorer ) ) + "\n\t<seq2seq4repair_space>Query=" ) + q ) + "<seq2seq4repair_space>" ) + ( q . getClass ( ) . getName ( ) ) ) + "\n\t<seq2seq4repair_space>Searcher=" ) + s ) + "\n\t<seq2seq4repair_space>Order=" ) + sbord ) + "\n\t<seq2seq4repair_space>Op=" ) + ( op == skip_op ? "<seq2seq4repair_space>skip()" : "<seq2seq4repair_space>next()" ) ) ) ; } } catch ( IOException e ) { throw new RuntimeException ( e ) ; } } @ Override public void setNextReader ( IndexReader reader , int docBase ) throws IOException { if ( ( lastReader [ 0 ] ) != null ) { final IndexReader previousReader = lastReader [ 0 ] ; Weight w = q . weight ( new IndexSearcher ( previousReader ) ) ; Scorer scorer = w . scorer ( previousReader , true , false ) ; if ( scorer != null ) { boolean more = ( scorer . advance ( ( ( lastDoc [ 0 ] ) + 1 ) ) ) != ( DocIdSetIterator . NO_MORE_DOCS ) ; Assert . assertFalse ( ( ( ( ( ( "query's<seq2seq4repair_space>last<seq2seq4repair_space>doc<seq2seq4repair_space>was<seq2seq4repair_space>" + ( lastDoc [ 0 ] ) ) + "<seq2seq4repair_space>but<seq2seq4repair_space>skipTo(" ) + ( ( lastDoc [ 0 ] ) + 1 ) ) + ")<seq2seq4repair_space>got<seq2seq4repair_space>to<seq2seq4repair_space>" ) + ( scorer . docID ( ) ) ) , more ) ; } } <START_BUG> this . reader = reader ; <END_BUG> this . scorer = null ; lastDoc [ 0 ] = - 1 ; } @ Override public boolean acceptsDocsOutOfOrder ( ) { return true ; } } ) ; if ( ( lastReader [ 0 ] ) != null ) { final IndexReader previousReader = lastReader [ 0 ] ; Weight w = q . weight ( new IndexSearcher ( previousReader ) ) ; Scorer scorer = w . scorer ( previousReader , true , false ) ; if ( scorer != null ) { boolean more = ( scorer . advance ( ( ( lastDoc [ 0 ] ) + 1 ) ) ) != ( DocIdSetIterator . NO_MORE_DOCS ) ; Assert . assertFalse ( ( ( ( ( ( "query's<seq2seq4repair_space>last<seq2seq4repair_space>doc<seq2seq4repair_space>was<seq2seq4repair_space>" + ( lastDoc [ 0 ] ) ) + "<seq2seq4repair_space>but<seq2seq4repair_space>skipTo(" ) + ( ( lastDoc [ 0 ] ) + 1 ) ) + ")<seq2seq4repair_space>got<seq2seq4repair_space>to<seq2seq4repair_space>" ) + ( scorer . docID ( ) ) ) , more ) ; } } } } private static void checkFirstSkipTo ( final Query q , final IndexSearcher s ) throws IOException { } }

Fix:
this . reader = lastReader [ 0 ] = reader ;