Buggy code:
} w . addDocument ( doc ) ; } reader = w . getReader ( ) ; <START_BUG> w . close ( ) ; <END_BUG> } final IndexSearcher searcher = newSearcher ( reader ) ; final IndexReaderContext ctx = searcher . getTopReaderContext ( ) ; final TestTopDocsMerge . ShardSearcher [ ] subSearchers ; final int [ ] docStarts ; if ( ctx instanceof AtomicReaderContext ) { subSearchers = new TestTopDocsMerge . ShardSearcher [ 1 ] ; docStarts = new int [ 1 ] ; subSearchers [ 0 ] = new TestTopDocsMerge . ShardSearcher ( ( ( AtomicReaderContext ) ( ctx ) ) , ctx ) ; docStarts [ 0 ] = 0 ; } else { final CompositeReaderContext compCTX = ( ( CompositeReaderContext ) ( ctx ) ) ; final int size = compCTX . leaves ( ) . size ( ) ; subSearchers = new TestTopDocsMerge . ShardSearcher [ size ] ; docStarts = new int [ size ] ; int docBase = 0 ; for ( int searcherIDX = 0 ; searcherIDX < ( subSearchers . length ) ; searcherIDX ++ ) { final AtomicReaderContext leave = compCTX . leaves ( ) . get ( searcherIDX ) ; subSearchers [ searcherIDX ] = new TestTopDocsMerge . ShardSearcher ( leave , compCTX ) ; docStarts [ searcherIDX ] = docBase ; docBase += leave . reader ( ) . maxDoc ( ) ; } } final List < SortField > sortFields = new ArrayList < > ( ) ; sortFields . add ( new SortField ( "string" , Type . STRING , true ) ) ; sortFields . add ( new SortField ( "string" , Type . STRING , false ) ) ; sortFields . add ( new SortField ( "int" , Type . INT , true ) ) ; sortFields . add ( new SortField ( "int" , Type . INT , false ) ) ; sortFields . add ( new SortField ( "float" , Type . FLOAT , true ) ) ; sortFields . add ( new SortField ( "float" , Type . FLOAT , false ) ) ; sortFields . add ( new SortField ( null , Type . SCORE , true ) ) ; sortFields . add ( new SortField ( null , Type . SCORE , false ) ) ; sortFields . add ( new SortField ( null , Type . DOC , true ) ) ; sortFields . add ( new SortField ( null , Type . DOC , false ) ) ; for ( int iter = 0 ; iter < ( 1000 * ( RANDOM_MULTIPLIER ) ) ; iter ++ ) { final Query query = new TermQuery ( new Term ( "text" , tokens [ random ( ) . nextInt ( tokens . length ) ] ) ) ; final Sort sort ; if ( ( random ( ) . nextInt ( 10 ) ) == 4 ) { sort = null ; } else { final SortField [ ] randomSortFields = new SortField [ TestUtil . nextInt ( random ( ) , 1 , 3 ) ] ; for ( int sortIDX = 0 ; sortIDX < ( randomSortFields . length ) ; sortIDX ++ ) { randomSortFields [ sortIDX ] = sortFields . get ( random ( ) . nextInt ( sortFields . size ( ) ) ) ; } sort = new Sort ( randomSortFields ) ; } final int numHits = TestUtil . nextInt ( random ( ) , 1 , ( numDocs + 5 ) ) ; if ( VERBOSE ) { System . out . println ( ( ( ( ( ( "TEST:<seq2seq4repair_space>search<seq2seq4repair_space>query=" + query ) + "<seq2seq4repair_space>sort=" ) + sort ) + "<seq2seq4repair_space>numHits=" ) + numHits ) ) ; } int from = - 1 ; int size = - 1 ; final TopDocs topHits ; if ( sort == null ) { if ( useFrom ) { TopScoreDocCollector c = TopScoreDocCollector . create ( numHits , random ( ) . nextBoolean ( ) ) ; searcher . search ( query , c ) ; from = TestUtil . nextInt ( random ( ) , 0 , ( numHits - 1 ) ) ; size = numHits - from ; TopDocs tempTopHits = c . topDocs ( ) ; if ( from < ( tempTopHits . scoreDocs . length ) ) { ScoreDoc [ ] newScoreDocs = new ScoreDoc [ Math . min ( size , ( ( tempTopHits . scoreDocs . length ) - from ) ) ] ; System . arraycopy ( tempTopHits . scoreDocs , from , newScoreDocs , 0 , newScoreDocs . length ) ; tempTopHits . scoreDocs = newScoreDocs ; topHits = tempTopHits ; } else { topHits = new TopDocs ( tempTopHits . totalHits , new ScoreDoc [ 0 ] , tempTopHits . getMaxScore ( ) ) ; } } else { topHits = searcher . search ( query , numHits ) ; } } else { final TopFieldCollector c = TopFieldCollector . create ( sort , numHits , true , true , true , random ( ) . nextBoolean ( ) ) ; searcher . search ( query , c ) ; if ( useFrom ) { from = TestUtil . nextInt ( random ( ) , 0 , ( numHits - 1 ) ) ; size = numHits - from ; TopDocs tempTopHits = c . topDocs ( ) ; if ( from < ( tempTopHits . scoreDocs . length ) ) { ScoreDoc [ ] newScoreDocs = new ScoreDoc [ Math . min ( size , ( ( tempTopHits . scoreDocs . length ) - from ) ) ] ; System . arraycopy ( tempTopHits . scoreDocs , from , newScoreDocs , 0 , newScoreDocs . length ) ; tempTopHits . scoreDocs = newScoreDocs ; topHits = tempTopHits ; } else { topHits = new TopDocs ( tempTopHits . totalHits , new ScoreDoc [ 0 ] , tempTopHits . getMaxScore ( ) ) ; } } else { topHits = c . topDocs ( 0 , numHits ) ; } } if ( VERBOSE ) { if ( useFrom ) { System . out . println ( ( ( ( "from=" + from ) + "<seq2seq4repair_space>size=" ) + size ) ) ; } System . out . println ( ( ( ( "<seq2seq4repair_space>top<seq2seq4repair_space>search:<seq2seq4repair_space>" + ( topHits . totalHits ) ) + "<seq2seq4repair_space>totalHits;<seq2seq4repair_space>hits="

Fix:
w . shutdown ( ) ;