Buggy code:
boolean done = false ; String methodName ; if ( 0 == method ) { methodName = "addIndexes(Directory[])<seq2seq4repair_space>+<seq2seq4repair_space>forceMerge(1)" ; } else if ( 1 == method ) { methodName = "addIndexes(IndexReader[])" ; } else { methodName = "addIndexes(Directory[])" ; } while ( ! done ) { if ( VERBOSE ) { System . out . println ( "TEST:<seq2seq4repair_space>cycle..." ) ; } MockDirectoryWrapper dir = new MockDirectoryWrapper ( random ( ) , new org . apache . lucene . store . RAMDirectory ( startDir , newIOContext ( random ( ) ) ) ) ; <START_BUG> writer = new IndexWriter ( dir , newIndexWriterConfig ( TEST_VERSION_CURRENT , new org . apache . lucene . analysis . MockAnalyzer ( random ( ) ) ) . setOpenMode ( APPEND ) . setMergePolicy ( newLogMergePolicy ( ) ) ) ; <END_BUG> IOException err = null ; MergeScheduler ms = writer . getConfig ( ) . getMergeScheduler ( ) ; for ( int x = 0 ; x < 2 ; x ++ ) { if ( ms instanceof ConcurrentMergeScheduler ) if ( 0 == x ) ( ( ConcurrentMergeScheduler ) ( ms ) ) . setSuppressExceptions ( ) ; else ( ( ConcurrentMergeScheduler ) ( ms ) ) . clearSuppressExceptions ( ) ; double rate = 0.05 ; double diskRatio = ( ( double ) ( diskFree ) ) // diskUsage ; long thisDiskFree ; String testName = null ; if ( 0 == x ) { thisDiskFree = diskFree ; if ( diskRatio >= 2.0 ) { rate //= 2 ; } if ( diskRatio >= 4.0 ) { rate //= 2 ; } if ( diskRatio >= 6.0 ) { rate = 0.0 ; } if ( VERBOSE ) testName = ( ( ( "disk<seq2seq4repair_space>full<seq2seq4repair_space>test<seq2seq4repair_space>" + methodName ) + "<seq2seq4repair_space>with<seq2seq4repair_space>disk<seq2seq4repair_space>full<seq2seq4repair_space>at<seq2seq4repair_space>" ) + diskFree ) + "<seq2seq4repair_space>bytes" ; } else { thisDiskFree = 0 ; rate = 0.0 ; if ( VERBOSE ) testName = ( "disk<seq2seq4repair_space>full<seq2seq4repair_space>test<seq2seq4repair_space>" + methodName ) + "<seq2seq4repair_space>with<seq2seq4repair_space>unlimited<seq2seq4repair_space>disk<seq2seq4repair_space>space" ; } if ( VERBOSE ) System . out . println ( ( "\ncycle:<seq2seq4repair_space>" + testName ) ) ; dir . setTrackDiskUsage ( true ) ; dir . setMaxSizeInBytes ( thisDiskFree ) ; dir . setRandomIOExceptionRate ( rate ) ; try { if ( 0 == method ) { if ( VERBOSE ) { System . out . println ( ( "TEST:<seq2seq4repair_space>now<seq2seq4repair_space>addIndexes<seq2seq4repair_space>count=" + ( dirs . length ) ) ) ; } writer . addIndexes ( dirs ) ; if ( VERBOSE ) { System . out . println ( "TEST:<seq2seq4repair_space>now<seq2seq4repair_space>forceMerge" ) ; } writer . forceMerge ( 1 ) ; } else if ( 1 == method ) { IndexReader [ ] readers = new IndexReader [ dirs . length ] ; for ( int i = 0 ; i < ( dirs . length ) ; i ++ ) { readers [ i ] = DirectoryReader . open ( dirs [ i ] ) ; } try { writer . addIndexes ( readers ) ; } finally { for ( int i = 0 ; i < ( dirs . length ) ; i ++ ) { readers [ i ] . close ( ) ; } } } else { writer . addIndexes ( dirs ) ; } success = true ; if ( VERBOSE ) { System . out . println ( "<seq2seq4repair_space>success!" ) ; } if ( 0 == x ) { done = true ; } } catch ( IOException e ) { success = false ; err = e ; if ( VERBOSE ) { System . out . println ( ( "<seq2seq4repair_space>hit<seq2seq4repair_space>IOException:<seq2seq4repair_space>" + e ) ) ; e . printStackTrace ( System . out ) ; } if ( 1 == x ) { e . printStackTrace ( System . out ) ; fail ( ( methodName + "<seq2seq4repair_space>hit<seq2seq4repair_space>IOException<seq2seq4repair_space>after<seq2seq4repair_space>disk<seq2seq4repair_space>space<seq2seq4repair_space>was<seq2seq4repair_space>freed<seq2seq4repair_space>up" ) ) ; } } _TestUtil . syncConcurrentMerges ( writer ) ; if ( VERBOSE ) { System . out . println ( "<seq2seq4repair_space>now<seq2seq4repair_space>test<seq2seq4repair_space>readers" ) ; } try { reader = DirectoryReader . open ( dir ) ; } catch ( IOException e ) { e . printStackTrace ( System . out ) ; fail ( ( ( testName + ":<seq2seq4repair_space>exception<seq2seq4repair_space>when<seq2seq4repair_space>creating<seq2seq4repair_space>IndexReader:<seq2seq4repair_space>" ) + e ) ) ; } int result = reader . docFreq ( searchTerm ) ; if ( success ) { if ( result != START_COUNT ) { fail ( ( ( ( ( testName + ":<seq2seq4repair_space>method<seq2seq4repair_space>did<seq2seq4repair_space>not<seq2seq4repair_space>throw<seq2seq4repair_space>exception<seq2seq4repair_space>but<seq2seq4repair_space>docFreq('aaa')<seq2seq4repair_space>is<seq2seq4repair_space>" ) + result ) + "<seq2seq4repair_space>instead<seq2seq4repair_space>of<seq2seq4repair_space>expected<seq2seq4repair_space>" ) + START_COUNT ) ) ; } } else { if ( ( result != START_COUNT ) && ( result != END_COUNT ) ) { err . printStackTrace ( System . out ) ; fail ( ( ( ( ( ( ( testName + ":<seq2seq4repair_space>method<seq2seq4repair_space>did<seq2seq4repair_space>throw<seq2seq4repair_space>exception<seq2seq4repair_space>but<seq2seq4repair_space>docFreq('aaa')<seq2seq4repair_space>is<seq2seq4repair_space>" ) + result ) + "<seq2seq4repair_space>instead<seq2seq4repair_space>of<seq2seq4repair_space>expected<seq2seq4repair_space>" ) + START_COUNT ) + "<seq2seq4repair_space>or<seq2seq4repair_space>" ) + END_COUNT ) ) ; } } searcher = newSearcher ( reader ) ; try { hits = searcher . search ( new org . apache . lucene . search . TermQuery ( searchTerm ) , null , END_COUNT ) . scoreDocs ; } catch ( IOException e ) { e . printStackTrace ( System . out ) ; fail ( ( ( testName + ":<seq2seq4repair_space>exception<seq2seq4repair_space>when<seq2seq4repair_space>searching:<seq2seq4repair_space>" ) + e ) ) ; } int result2 = hits . length ; if ( success ) { if ( result2 != result ) { fail ( ( ( ( ( testName + ":<seq2seq4repair_space>method<seq2seq4repair_space>did<seq2seq4repair_space>not<seq2seq4repair_space>throw<seq2seq4repair_space>exception<seq2seq4repair_space>but<seq2seq4repair_space>hits.length<seq2seq4repair_space>for<seq2seq4repair_space>search<seq2seq4repair_space>on<seq2seq4repair_space>term<seq2seq4repair_space>'aaa'<seq2seq4repair_space>is<seq2seq4repair_space>" ) + result2 ) + "<seq2seq4repair_space>instead<seq2seq4repair_space>of<seq2seq4repair_space>expected<seq2seq4repair_space>" ) + result ) ) ; } } else { if ( result2 != result ) { err . printStackTrace ( System . out ) ; fail ( ( ( ( ( testName + ":<seq2seq4repair_space>method<seq2seq4repair_space>did<seq2seq4repair_space>throw<seq2seq4repair_space>exception<seq2seq4repair_space>but<seq2seq4repair_space>hits.length<seq2seq4repair_space>for<seq2seq4repair_space>search<seq2seq4repair_space>on<seq2seq4repair_space>term<seq2seq4repair_space>'aaa'<seq2seq4repair_space>is<seq2seq4repair_space>" ) + result2 ) + "<seq2seq4repair_space>instead<seq2seq4repair_space>of<seq2seq4repair_space>expected<seq2seq4repair_space>" ) + result ) ) ; } } reader . close ( ) ; if ( VERBOSE ) { System . out . println ( ( "<seq2seq4repair_space>count<seq2seq4repair_space>is<seq2seq4repair_space>" + result ) ) ; } if ( done || ( result == END_COUNT ) ) { break ; } } if ( VERBOSE ) { System . out . println ( ( ( ( ( ( "<seq2seq4repair_space>start<seq2seq4repair_space>disk<seq2seq4repair_space>=<seq2seq4repair_space>" + startDiskUsage ) + ";<seq2seq4repair_space>input<seq2seq4repair_space>disk<seq2seq4repair_space>=<seq2seq4repair_space>" ) + inputDiskUsage ) + ";<seq2seq4repair_space>max<seq2seq4repair_space>used<seq2seq4repair_space>=<seq2seq4repair_space>" ) + ( dir . getMaxUsedSizeInBytes ( ) ) ) ) ; } if ( done ) { assertTrue ( ( ( ( ( ( ( ( ( ( ( ( "max<seq2seq4repair_space>free<seq2seq4repair_space>Directory<seq2seq4repair_space>space<seq2seq4repair_space>required<seq2seq4repair_space>exceeded<seq2seq4repair_space>1X<seq2seq4repair_space>the<seq2seq4repair_space>total<seq2seq4repair_space>input<seq2seq4repair_space>index<seq2seq4repair_space>sizes<seq2seq4repair_space>during<seq2seq4repair_space>" + methodName ) + ":<seq2seq4repair_space>max<seq2seq4repair_space>temp<seq2seq4repair_space>usage<seq2seq4repair_space>=<seq2seq4repair_space>" ) + ( ( dir . getMaxUsedSizeInBytes ( ) ) - startDiskUsage ) ) + "<seq2seq4repair_space>bytes<seq2seq4repair_space>vs<seq2seq4repair_space>limit=" ) + ( 2 * ( startDiskUsage + inputDiskUsage ) ) ) + ";<seq2seq4repair_space>starting<seq2seq4repair_space>disk<seq2seq4repair_space>usage<seq2seq4repair_space>=<seq2seq4repair_space>" ) + startDiskUsage ) + "<seq2seq4repair_space>bytes;<seq2seq4repair_space>"

Fix:
writer = new IndexWriter ( dir , newIndexWriterConfig ( TEST_VERSION_CURRENT , new org . apache . lucene . analysis . MockAnalyzer ( random ( ) ) ) . setOpenMode ( APPEND ) . setMergePolicy ( newLogMergePolicy ( false ) ) ) ;