Buggy code:
public class TestBufferedIndexInput extends LuceneTestCase { private static void writeBytes ( File aFile , long size ) throws IOException { } private static final long TEST_FILE_LENGTH = 100 * 1024 ; public void testReadByte ( ) throws Exception { } public void testReadBytes ( ) throws Exception { } private void runReadBytesAndClose ( IndexInput input , int bufferSize , Random r ) throws IOException { } private void runReadBytes ( IndexInput input , int bufferSize , Random r ) throws IOException { } private byte [ ] buffer = new byte [ 10 ] ; private void checkReadBytes ( IndexInput input , int size , int pos ) throws IOException { } public void testEOF ( ) throws Exception { } private static byte byten ( long n ) { } private static class MyBufferedIndexInput extends BufferedIndexInput { private long pos ; private long len ; public MyBufferedIndexInput ( long len ) { } public MyBufferedIndexInput ( ) { } @ Override protected void readInternal ( byte [ ] b , int offset , int length ) throws IOException { } @ Override protected void seekInternal ( long pos ) throws IOException { } @ Override public void close ( ) throws IOException { } @ Override public long length ( ) { } } public void testSetBufferSize ( ) throws IOException { File indexDir = createTempDir ( "testSetBufferSize" ) ; TestBufferedIndexInput . MockFSDirectory dir = new TestBufferedIndexInput . MockFSDirectory ( indexDir , random ( ) ) ; try { IndexWriter writer = new IndexWriter ( dir , new org . apache . lucene . index . IndexWriterConfig ( TEST_VERSION_CURRENT , new org . apache . lucene . analysis . MockAnalyzer ( random ( ) ) ) . setOpenMode ( CREATE ) . setMergePolicy ( newLogMergePolicy ( false ) ) ) ; for ( int i = 0 ; i < 37 ; i ++ ) { Document doc = new Document ( ) ; doc . add ( newTextField ( "content" , ( "aaa<seq2seq4repair_space>bbb<seq2seq4repair_space>ccc<seq2seq4repair_space>ddd" + i ) , YES ) ) ; doc . add ( newTextField ( "id" , ( "" + i ) , YES ) ) ; writer . addDocument ( doc ) ; } dir . allIndexInputs . clear ( ) ; IndexReader reader = DirectoryReader . open ( writer , true ) ; Term aaa = new Term ( "content" , "aaa" ) ; Term bbb = new Term ( "content" , "bbb" ) ; reader . close ( ) ; dir . tweakBufferSizes ( ) ; writer . deleteDocuments ( new Term ( "id" , "0" ) ) ; reader = DirectoryReader . open ( writer , true ) ; IndexSearcher searcher = newSearcher ( reader ) ; ScoreDoc [ ] hits = searcher . search ( new org . apache . lucene . search . TermQuery ( bbb ) , null , 1000 ) . scoreDocs ; dir . tweakBufferSizes ( ) ; assertEquals ( 36 , hits . length ) ; reader . close ( ) ; dir . tweakBufferSizes ( ) ; writer . deleteDocuments ( new Term ( "id" , "4" ) ) ; reader = DirectoryReader . open ( writer , true ) ; searcher = newSearcher ( reader ) ; hits = searcher . search ( new org . apache . lucene . search . TermQuery ( bbb ) , null , 1000 ) . scoreDocs ; dir . tweakBufferSizes ( ) ; assertEquals ( 35 , hits . length ) ; dir . tweakBufferSizes ( ) ; hits = searcher . search ( new org . apache . lucene . search . TermQuery ( new Term ( "id" , "33" ) ) , null , 1000 ) . scoreDocs ; dir . tweakBufferSizes ( ) ; assertEquals ( 1 , hits . length ) ; hits = searcher . search ( new org . apache . lucene . search . TermQuery ( aaa ) , null , 1000 ) . scoreDocs ; dir . tweakBufferSizes ( ) ; assertEquals ( 35 , hits . length ) ; <START_BUG> writer . close ( ) ; <END_BUG> reader . close ( ) ; } finally { TestUtil . rm ( indexDir ) ; } } private static class MockFSDirectory extends BaseDirectory { List < IndexInput > allIndexInputs = new ArrayList < > ( ) ; Random rand ; private Directory dir ; public MockFSDirectory ( File path , Random rand ) throws IOException { } public void tweakBufferSizes ( ) { } @ Override public IndexInput openInput ( String name , IOContext context ) throws IOException { } @ Override public IndexOutput createOutput ( String name , IOContext context ) throws IOException { } @ Override public void close ( ) throws IOException { } @ Override public void deleteFile ( String name ) throws IOException { } @ Override public String [ ] listAll ( ) throws IOException { } @ Override public void sync ( Collection < String > names ) throws IOException { } @ Override public long fileLength ( String name ) throws IOException { } } }

Fix:
writer . shutdown ( ) ;