Buggy code:
verbose ( "adding<seq2seq4repair_space>tombstone<seq2seq4repair_space>for<seq2seq4repair_space>id" , id , "val=" , nextVal ) ; writer . updateDocument ( new Term ( "id" , ( "-" + ( Integer . toString ( id ) ) ) ) , d ) ; } verbose ( "deleting<seq2seq4repair_space>id" , id , "val=" , nextVal ) ; writer . deleteDocuments ( new Term ( "id" , Integer . toString ( id ) ) ) ; model . put ( id , new DocInfo ( 0 , ( - nextVal ) ) ) ; verbose ( "deleting<seq2seq4repair_space>id" , id , "val=" , nextVal , "DONE" ) ; } else if ( oper < ( ( commitPercent + deletePercent ) + deleteByQueryPercent ) ) { if ( tombstones ) { Document d = new Document ( ) ; d . add ( new org . apache . lucene . document . Field ( "id" , ( "-" + ( Integer . toString ( id ) ) ) , idFt ) ) ; d . add ( new org . apache . lucene . document . Field ( field , Long . toString ( nextVal ) , ft2 ) ) ; verbose ( "adding<seq2seq4repair_space>tombstone<seq2seq4repair_space>for<seq2seq4repair_space>id" , id , "val=" , nextVal ) ; writer . updateDocument ( new Term ( "id" , ( "-" + ( Integer . toString ( id ) ) ) ) , d ) ; } verbose ( "deleteByQuery" , id , "val=" , nextVal ) ; writer . deleteDocuments ( new org . apache . lucene . search . TermQuery ( new Term ( "id" , Integer . toString ( id ) ) ) ) ; model . put ( id , new DocInfo ( 0 , ( - nextVal ) ) ) ; verbose ( "deleteByQuery" , id , "val=" , nextVal , "DONE" ) ; } else { Document d = new Document ( ) ; d . add ( new org . apache . lucene . document . Field ( "id" , Integer . toString ( id ) , idFt ) ) ; d . add ( new org . apache . lucene . document . Field ( field , Long . toString ( nextVal ) , ft2 ) ) ; verbose ( "adding<seq2seq4repair_space>id" , id , "val=" , nextVal ) ; writer . updateDocument ( new Term ( "id" , Integer . toString ( id ) ) , d ) ; if ( tombstones ) { verbose ( "deleting<seq2seq4repair_space>tombstone<seq2seq4repair_space>for<seq2seq4repair_space>id" , id ) ; writer . deleteDocuments ( new Term ( "id" , ( "-" + ( Integer . toString ( id ) ) ) ) ) ; verbose ( "deleting<seq2seq4repair_space>tombstone<seq2seq4repair_space>for<seq2seq4repair_space>id" , id , "DONE" ) ; } model . put ( id , new DocInfo ( 0 , nextVal ) ) ; verbose ( "adding<seq2seq4repair_space>id" , id , "val=" , nextVal , "DONE" ) ; } } if ( ! before ) { lastId = id ; } } } catch ( Exception ex ) { throw new RuntimeException ( ex ) ; } } } ; threads . add ( thread ) ; } for ( int i = 0 ; i < nReadThreads ; i ++ ) { Thread thread = new Thread ( ( "READER" + i ) ) { Random rand = new Random ( random ( ) . nextInt ( ) ) ; @ Override public void run ( ) { try { while ( ( operations . decrementAndGet ( ) ) >= 0 ) { int id = ( ( rand . nextInt ( 100 ) ) < 25 ) ? lastId : rand . nextInt ( ndocs ) ; DocInfo info ; synchronized ( globalLock ) { info = committedModel . get ( id ) ; } long val = info . val ; IndexReader r ; synchronized ( globalLock ) { r = reader ; r . incRef ( ) ; } int docid = getFirstMatch ( r , new Term ( "id" , Integer . toString ( id ) ) ) ; if ( ( docid < 0 ) && tombstones ) { docid = getFirstMatch ( r , new Term ( "id" , ( "-" + ( Integer . toString ( id ) ) ) ) ) ; if ( docid < 0 ) { if ( val == ( - 1L ) ) { r . decRef ( ) ; continue ; } verbose ( "ERROR:<seq2seq4repair_space>Couldn't<seq2seq4repair_space>find<seq2seq4repair_space>a<seq2seq4repair_space>doc<seq2seq4repair_space>or<seq2seq4repair_space>tombstone<seq2seq4repair_space>for<seq2seq4repair_space>id" , id , "using<seq2seq4repair_space>reader" , r , "expected<seq2seq4repair_space>value" , val ) ; fail ( ( ( ( "No<seq2seq4repair_space>documents<seq2seq4repair_space>or<seq2seq4repair_space>tombstones<seq2seq4repair_space>found<seq2seq4repair_space>for<seq2seq4repair_space>id<seq2seq4repair_space>" + id ) + ",<seq2seq4repair_space>expected<seq2seq4repair_space>at<seq2seq4repair_space>least<seq2seq4repair_space>" ) + val ) ) ; } } if ( ( docid < 0 ) && ( ! tombstones ) ) { } else { if ( docid < 0 ) { verbose ( "ERROR:<seq2seq4repair_space>Couldn't<seq2seq4repair_space>find<seq2seq4repair_space>a<seq2seq4repair_space>doc<seq2seq4repair_space>for<seq2seq4repair_space>id" , id , "using<seq2seq4repair_space>reader" , r ) ; } assertTrue ( ( docid >= 0 ) ) ; StoredDocument doc = r . document ( docid ) ; long foundVal = Long . parseLong ( doc . get ( field ) ) ; if ( foundVal < ( Math . abs ( val ) ) ) { verbose ( "ERROR:<seq2seq4repair_space>id" , id , "model_val=" , val , "<seq2seq4repair_space>foundVal=" , foundVal , "reader=" , reader ) ; } assertTrue ( ( foundVal >= ( Math . abs ( val ) ) ) ) ; } r . decRef ( ) ; } } catch ( Throwable e ) { operations . set ( ( - 1L ) ) ; throw new RuntimeException ( e ) ; } } } ; threads . add ( thread ) ; } for ( Thread thread : threads ) { thread . start ( ) ; } for ( Thread thread : threads ) { thread . join ( ) ; } <START_BUG> writer . close ( ) ; <END_BUG> reader . close ( ) ; dir . close ( ) ; } }

Fix:
writer . shutdown ( ) ;