Buggy code:
sf2 . setMissingValue ( random ( ) . nextInt ( ) ) ; allSortFields . add ( sf2 ) ; } else if ( ( sf . getType ( ) ) == ( Type . LONG ) ) { SortField sf2 = new SortField ( sf . getField ( ) , Type . LONG , sf . getReverse ( ) ) ; sf2 . setMissingValue ( random ( ) . nextLong ( ) ) ; allSortFields . add ( sf2 ) ; } else if ( ( sf . getType ( ) ) == ( Type . FLOAT ) ) { SortField sf2 = new SortField ( sf . getField ( ) , Type . FLOAT , sf . getReverse ( ) ) ; sf2 . setMissingValue ( random ( ) . nextFloat ( ) ) ; allSortFields . add ( sf2 ) ; } else if ( ( sf . getType ( ) ) == ( Type . DOUBLE ) ) { SortField sf2 = new SortField ( sf . getField ( ) , Type . DOUBLE , sf . getReverse ( ) ) ; sf2 . setMissingValue ( random ( ) . nextDouble ( ) ) ; allSortFields . add ( sf2 ) ; } } dir = newDirectory ( ) ; RandomIndexWriter iw = new RandomIndexWriter ( random ( ) , dir ) ; int numDocs = atLeast ( 200 ) ; for ( int i = 0 ; i < numDocs ; i ++ ) { List < Field > fields = new ArrayList < > ( ) ; fields . add ( newTextField ( "english" , English . intToEnglish ( i ) , NO ) ) ; fields . add ( newTextField ( "oddeven" , ( ( i % 2 ) == 0 ? "even" : "odd" ) , NO ) ) ; fields . add ( newStringField ( "byte" , ( "" + ( ( byte ) ( random ( ) . nextInt ( ) ) ) ) , NO ) ) ; fields . add ( newStringField ( "short" , ( "" + ( ( short ) ( random ( ) . nextInt ( ) ) ) ) , NO ) ) ; fields . add ( new org . apache . lucene . document . IntField ( "int" , random ( ) . nextInt ( ) , Store . NO ) ) ; fields . add ( new org . apache . lucene . document . LongField ( "long" , random ( ) . nextLong ( ) , Store . NO ) ) ; fields . add ( new org . apache . lucene . document . FloatField ( "float" , random ( ) . nextFloat ( ) , Store . NO ) ) ; fields . add ( new org . apache . lucene . document . DoubleField ( "double" , random ( ) . nextDouble ( ) , Store . NO ) ) ; fields . add ( newStringField ( "bytes" , TestUtil . randomRealisticUnicodeString ( random ( ) ) , NO ) ) ; fields . add ( newStringField ( "bytesval" , TestUtil . randomRealisticUnicodeString ( random ( ) ) , NO ) ) ; fields . add ( new org . apache . lucene . document . DoubleField ( "double" , random ( ) . nextDouble ( ) , Store . NO ) ) ; fields . add ( new org . apache . lucene . document . NumericDocValuesField ( "intdocvalues" , random ( ) . nextInt ( ) ) ) ; fields . add ( new org . apache . lucene . document . FloatDocValuesField ( "floatdocvalues" , random ( ) . nextFloat ( ) ) ) ; fields . add ( new SortedDocValuesField ( "sortedbytesdocvalues" , new org . apache . lucene . util . BytesRef ( TestUtil . randomRealisticUnicodeString ( random ( ) ) ) ) ) ; fields . add ( new SortedDocValuesField ( "sortedbytesdocvaluesval" , new org . apache . lucene . util . BytesRef ( TestUtil . randomRealisticUnicodeString ( random ( ) ) ) ) ) ; fields . add ( new BinaryDocValuesField ( "straightbytesdocvalues" , new org . apache . lucene . util . BytesRef ( TestUtil . randomRealisticUnicodeString ( random ( ) ) ) ) ) ; Document document = new Document ( ) ; document . add ( new StoredField ( "id" , ( "" + i ) ) ) ; if ( VERBOSE ) { System . out . println ( ( "<seq2seq4repair_space>add<seq2seq4repair_space>doc<seq2seq4repair_space>id=" + i ) ) ; } for ( Field field : fields ) { if ( ( random ( ) . nextInt ( 5 ) ) != 4 ) { document . add ( field ) ; if ( VERBOSE ) { System . out . println ( ( "<seq2seq4repair_space>" + field ) ) ; } } } iw . addDocument ( document ) ; if ( ( random ( ) . nextInt ( 50 ) ) == 17 ) { iw . commit ( ) ; } } reader = iw . getReader ( ) ; <START_BUG> iw . close ( ) ; <END_BUG> searcher = newSearcher ( reader ) ; if ( VERBOSE ) { System . out . println ( ( "<seq2seq4repair_space>searcher=" + ( searcher ) ) ) ; } } @ Override public void tearDown ( ) throws Exception { } public void testQueries ( ) throws Exception { } void assertQuery ( Query query , Filter filter ) throws Exception { } Sort getRandomSort ( ) { } void assertQuery ( Query query , Filter filter , Sort sort ) throws Exception { } void assertPage ( int pageStart , TopDocs all , TopDocs paged ) throws IOException { } }

Fix:
iw . shutdown ( ) ;