Buggy code:
public class TestSpellChecker extends LuceneTestCase { private TestSpellChecker . SpellCheckerMock spellChecker ; private Directory userindex ; private Directory spellindex ; private List < IndexSearcher > searchers ; @ Override public void setUp ( ) throws Exception { super . setUp ( ) ; userindex = newDirectory ( ) ; IndexWriter writer = new IndexWriter ( userindex , new org . apache . lucene . index . IndexWriterConfig ( TEST_VERSION_CURRENT , new org . apache . lucene . analysis . MockAnalyzer ( random ( ) ) ) ) ; for ( int i = 0 ; i < 1000 ; i ++ ) { Document doc = new Document ( ) ; doc . add ( newTextField ( "field1" , English . intToEnglish ( i ) , YES ) ) ; doc . add ( newTextField ( "field2" , English . intToEnglish ( ( i + 1 ) ) , YES ) ) ; doc . add ( newTextField ( "field3" , ( "fvei" + ( ( i % 2 ) == 0 ? "<seq2seq4repair_space>five" : "" ) ) , YES ) ) ; writer . addDocument ( doc ) ; } { Document doc = new Document ( ) ; doc . add ( newTextField ( "field1" , "eight" , YES ) ) ; writer . addDocument ( doc ) ; } { Document doc = new Document ( ) ; doc . add ( newTextField ( "field1" , "twenty-one<seq2seq4repair_space>twenty-one" , YES ) ) ; writer . addDocument ( doc ) ; } { Document doc = new Document ( ) ; doc . add ( newTextField ( "field1" , "twenty" , YES ) ) ; writer . addDocument ( doc ) ; } <START_BUG> writer . close ( ) ; <END_BUG> searchers = Collections . synchronizedList ( new ArrayList < IndexSearcher > ( ) ) ; spellindex = newDirectory ( ) ; spellChecker = new TestSpellChecker . SpellCheckerMock ( spellindex ) ; } @ Override public void tearDown ( ) throws Exception { } public void testBuild ( ) throws IOException { } public void testComparator ( ) throws Exception { } public void testBogusField ( ) throws Exception { } public void testSuggestModes ( ) throws Exception { } private void checkCommonSuggestions ( IndexReader r ) throws IOException { } private void checkLevenshteinSuggestions ( IndexReader r ) throws IOException { } private void checkJaroWinklerSuggestions ( ) throws IOException { } private void checkNGramSuggestions ( ) throws IOException { } private void addwords ( IndexReader r , SpellChecker sc , String field ) throws IOException { } private int numdoc ( ) throws IOException { } public void testClose ( ) throws IOException { } public void testConcurrentAccess ( ) throws IOException , InterruptedException { } private void assertLastSearcherOpen ( int numSearchers ) { } private void assertSearchersClosed ( ) { } private class SpellCheckWorker implements Runnable { private final IndexReader reader ; volatile boolean terminated = false ; volatile boolean failed = false ; SpellCheckWorker ( IndexReader reader ) { } @ Override public void run ( ) { } } class SpellCheckerMock extends SpellChecker { public SpellCheckerMock ( Directory spellIndex ) throws IOException { } public SpellCheckerMock ( Directory spellIndex , StringDistance sd ) throws IOException { } public SpellCheckerMock ( Directory spellIndex , StringDistance sd , Comparator < SuggestWord > comparator ) throws IOException { } @ Override IndexSearcher createSearcher ( Directory dir ) throws IOException { } } }

Fix:
writer . shutdown ( ) ;