Buggy code:
public class TestAddIndexes extends LuceneTestCase { public void testSimpleCase ( ) throws IOException { } public void testWithPendingDeletes ( ) throws IOException { } public void testWithPendingDeletes2 ( ) throws IOException { } public void testWithPendingDeletes3 ( ) throws IOException { } public void testAddSelf ( ) throws IOException { } public void testNoTailSegments ( ) throws IOException { } public void testNoCopySegments ( ) throws IOException { } public void testNoMergeAfterCopy ( ) throws IOException { } public void testMergeAfterCopy ( ) throws IOException { } public void testMoreMerges ( ) throws IOException { } private IndexWriter newWriter ( Directory dir , IndexWriterConfig conf ) throws IOException { } private void addDocs ( IndexWriter writer , int numDocs ) throws IOException { } private void addDocs2 ( IndexWriter writer , int numDocs ) throws IOException { } private void verifyNumDocs ( Directory dir , int numDocs ) throws IOException { } private void verifyTermDocs ( Directory dir , Term term , int numDocs ) throws IOException { } private void setUpDirs ( Directory dir , Directory aux ) throws IOException { } public void testHangOnClose ( ) throws IOException { } private void addDoc ( IndexWriter writer ) throws IOException { } private abstract class RunAddIndexesThreads { Directory dir ; Directory dir2 ; static final int NUM_INIT_DOCS = 17 ; IndexWriter writer2 ; final List < Throwable > failures = new ArrayList < Throwable > ( ) ; volatile boolean didClose ; final IndexReader [ ] readers ; final int NUM_COPY ; static final int NUM_THREADS = 5 ; final Thread [ ] threads = new Thread [ TestAddIndexes . RunAddIndexesThreads . NUM_THREADS ] ; public RunAddIndexesThreads ( int numCopy ) throws Throwable { } void launchThreads ( final int numIter ) { } void joinThreads ( ) throws Exception { } void close ( boolean doWait ) throws Throwable { } void closeDir ( ) throws Throwable { } abstract void doBody ( int j , Directory [ ] dirs ) throws Throwable { } abstract void handle ( Throwable t ) { } } private class CommitAndAddIndexes extends TestAddIndexes . RunAddIndexesThreads { public CommitAndAddIndexes ( int numCopy ) throws Throwable { } @ Override void handle ( Throwable t ) { } @ Override void doBody ( int j , Directory [ ] dirs ) throws Throwable { } } public void testAddIndexesWithThreads ( ) throws Throwable { } private class CommitAndAddIndexes2 extends TestAddIndexes . CommitAndAddIndexes { public CommitAndAddIndexes2 ( int numCopy ) throws Throwable { } @ Override void handle ( Throwable t ) { } } public void testAddIndexesWithClose ( ) throws Throwable { } private class CommitAndAddIndexes3 extends TestAddIndexes . RunAddIndexesThreads { public CommitAndAddIndexes3 ( int numCopy ) throws Throwable { } @ Override void doBody ( int j , Directory [ ] dirs ) throws Throwable { } @ Override void handle ( Throwable t ) { } } public void testAddIndexesWithCloseNoWait ( ) throws Throwable { final int NUM_COPY = 50 ; TestAddIndexes . CommitAndAddIndexes3 c = new TestAddIndexes . CommitAndAddIndexes3 ( NUM_COPY ) ; if ( VERBOSE ) { c . writer2 . setInfoStream ( System . out ) ; } c . launchThreads ( ( - 1 ) ) ; <START_BUG> Thread . sleep ( 500 ) ; <END_BUG> if ( VERBOSE ) { System . out . println ( "TEST:<seq2seq4repair_space>now<seq2seq4repair_space>close(false)" ) ; } c . close ( false ) ; c . joinThreads ( ) ; if ( VERBOSE ) { System . out . println ( "TEST:<seq2seq4repair_space>done<seq2seq4repair_space>join<seq2seq4repair_space>threads" ) ; } _TestUtil . checkIndex ( c . dir2 ) ; c . closeDir ( ) ; assertTrue ( ( ( c . failures . size ( ) ) == 0 ) ) ; } public void testAddIndexesWithRollback ( ) throws Throwable { } private void addDocs3 ( IndexWriter writer , int numDocs ) throws IOException { } public void testSimpleCaseCustomCodecProvider ( ) throws IOException { } public static class MockCodecProvider extends CodecProvider { public MockCodecProvider ( ) { } } }

Fix:
Thread . sleep ( _TestUtil . nextInt ( random , 10 , 500 ) ) ;