Buggy code:
@ Ignore public abstract class FunctionTestSetup extends LuceneTestCase { protected static float TEST_SCORE_TOLERANCE_DELTA = 0.001F ; protected static final int N_DOCS = 17 ; protected static final String ID_FIELD = "id" ; protected static final String TEXT_FIELD = "text" ; protected static final String INT_FIELD = "iii" ; protected static final String FLOAT_FIELD = "fff" ; private static final FloatParser CUSTOM_FLOAT_PARSER = new FieldCache . FloatParser ( ) { @ Override public TermsEnum termsEnum ( Terms terms ) throws IOException { } @ Override public float parseFloat ( BytesRef term ) { } } ; protected ValueSource INT_VALUESOURCE = new IntFieldSource ( FunctionTestSetup . INT_FIELD ) ; protected ValueSource INT_AS_FLOAT_VALUESOURCE = new FloatFieldSource ( FunctionTestSetup . INT_FIELD , FunctionTestSetup . CUSTOM_FLOAT_PARSER ) ; protected ValueSource FLOAT_VALUESOURCE = new FloatFieldSource ( FunctionTestSetup . FLOAT_FIELD ) ; private static final String [ ] DOC_TEXT_LINES = new String [ ] { "Well,<seq2seq4repair_space>this<seq2seq4repair_space>is<seq2seq4repair_space>just<seq2seq4repair_space>some<seq2seq4repair_space>plain<seq2seq4repair_space>text<seq2seq4repair_space>we<seq2seq4repair_space>use<seq2seq4repair_space>for<seq2seq4repair_space>creating<seq2seq4repair_space>the<seq2seq4repair_space>" , "test<seq2seq4repair_space>documents.<seq2seq4repair_space>It<seq2seq4repair_space>used<seq2seq4repair_space>to<seq2seq4repair_space>be<seq2seq4repair_space>a<seq2seq4repair_space>text<seq2seq4repair_space>from<seq2seq4repair_space>an<seq2seq4repair_space>online<seq2seq4repair_space>collection<seq2seq4repair_space>" , "devoted<seq2seq4repair_space>to<seq2seq4repair_space>first<seq2seq4repair_space>aid,<seq2seq4repair_space>but<seq2seq4repair_space>if<seq2seq4repair_space>there<seq2seq4repair_space>was<seq2seq4repair_space>there<seq2seq4repair_space>an<seq2seq4repair_space>(online)<seq2seq4repair_space>lawyers<seq2seq4repair_space>" , "first<seq2seq4repair_space>aid<seq2seq4repair_space>collection<seq2seq4repair_space>with<seq2seq4repair_space>legal<seq2seq4repair_space>advices,<seq2seq4repair_space>\"it\"<seq2seq4repair_space>might<seq2seq4repair_space>have<seq2seq4repair_space>quite<seq2seq4repair_space>" , "probably<seq2seq4repair_space>advised<seq2seq4repair_space>one<seq2seq4repair_space>not<seq2seq4repair_space>to<seq2seq4repair_space>include<seq2seq4repair_space>\"it\"\'s<seq2seq4repair_space>text<seq2seq4repair_space>or<seq2seq4repair_space>the<seq2seq4repair_space>text<seq2seq4repair_space>of<seq2seq4repair_space>" , "any<seq2seq4repair_space>other<seq2seq4repair_space>online<seq2seq4repair_space>collection<seq2seq4repair_space>in<seq2seq4repair_space>one's<seq2seq4repair_space>code,<seq2seq4repair_space>unless<seq2seq4repair_space>one<seq2seq4repair_space>has<seq2seq4repair_space>money<seq2seq4repair_space>" , "that<seq2seq4repair_space>one<seq2seq4repair_space>don't<seq2seq4repair_space>need<seq2seq4repair_space>and<seq2seq4repair_space>one<seq2seq4repair_space>is<seq2seq4repair_space>happy<seq2seq4repair_space>to<seq2seq4repair_space>donate<seq2seq4repair_space>for<seq2seq4repair_space>lawyers<seq2seq4repair_space>" , "charity.<seq2seq4repair_space>Anyhow<seq2seq4repair_space>at<seq2seq4repair_space>some<seq2seq4repair_space>point,<seq2seq4repair_space>rechecking<seq2seq4repair_space>the<seq2seq4repair_space>usage<seq2seq4repair_space>of<seq2seq4repair_space>this<seq2seq4repair_space>text,<seq2seq4repair_space>" , "it<seq2seq4repair_space>became<seq2seq4repair_space>uncertain<seq2seq4repair_space>that<seq2seq4repair_space>this<seq2seq4repair_space>text<seq2seq4repair_space>is<seq2seq4repair_space>free<seq2seq4repair_space>to<seq2seq4repair_space>use,<seq2seq4repair_space>because<seq2seq4repair_space>" , "the<seq2seq4repair_space>web<seq2seq4repair_space>site<seq2seq4repair_space>in<seq2seq4repair_space>the<seq2seq4repair_space>disclaimer<seq2seq4repair_space>of<seq2seq4repair_space>he<seq2seq4repair_space>eBook<seq2seq4repair_space>containing<seq2seq4repair_space>that<seq2seq4repair_space>text<seq2seq4repair_space>" , "was<seq2seq4repair_space>not<seq2seq4repair_space>responding<seq2seq4repair_space>anymore,<seq2seq4repair_space>and<seq2seq4repair_space>at<seq2seq4repair_space>the<seq2seq4repair_space>same<seq2seq4repair_space>time,<seq2seq4repair_space>in<seq2seq4repair_space>projGut,<seq2seq4repair_space>" , "searching<seq2seq4repair_space>for<seq2seq4repair_space>first<seq2seq4repair_space>aid<seq2seq4repair_space>no<seq2seq4repair_space>longer<seq2seq4repair_space>found<seq2seq4repair_space>that<seq2seq4repair_space>eBook<seq2seq4repair_space>as<seq2seq4repair_space>well.<seq2seq4repair_space>" , "So<seq2seq4repair_space>here<seq2seq4repair_space>we<seq2seq4repair_space>are,<seq2seq4repair_space>with<seq2seq4repair_space>a<seq2seq4repair_space>perhaps<seq2seq4repair_space>much<seq2seq4repair_space>less<seq2seq4repair_space>interesting<seq2seq4repair_space>" , "text<seq2seq4repair_space>for<seq2seq4repair_space>the<seq2seq4repair_space>test,<seq2seq4repair_space>but<seq2seq4repair_space>oh<seq2seq4repair_space>much<seq2seq4repair_space>much<seq2seq4repair_space>safer.<seq2seq4repair_space>" } ; protected static Directory dir ; protected static Analyzer anlzr ; @ AfterClass public static void afterClassFunctionTestSetup ( ) throws Exception { } protected static void createIndex ( boolean doMultiSegment ) throws Exception { if ( VERBOSE ) { System . out . println ( "TEST:<seq2seq4repair_space>setUp" ) ; } FunctionTestSetup . dir = newDirectory ( ) ; FunctionTestSetup . anlzr = new org . apache . lucene . analysis . MockAnalyzer ( random ( ) ) ; IndexWriterConfig iwc = newIndexWriterConfig ( TEST_VERSION_CURRENT , FunctionTestSetup . anlzr ) . setMergePolicy ( newLogMergePolicy ( ) ) ; if ( doMultiSegment ) { iwc . setMaxBufferedDocs ( TestUtil . nextInt ( random ( ) , 2 , 7 ) ) ; } RandomIndexWriter iw = new RandomIndexWriter ( random ( ) , FunctionTestSetup . dir , iwc ) ; int remaining = FunctionTestSetup . N_DOCS ; boolean [ ] done = new boolean [ FunctionTestSetup . N_DOCS ] ; int i = 0 ; while ( remaining > 0 ) { if ( done [ i ] ) { throw new Exception ( ( ( "to<seq2seq4repair_space>set<seq2seq4repair_space>this<seq2seq4repair_space>test<seq2seq4repair_space>correctly<seq2seq4repair_space>N_DOCS=" + ( FunctionTestSetup . N_DOCS ) ) + "<seq2seq4repair_space>must<seq2seq4repair_space>be<seq2seq4repair_space>primary<seq2seq4repair_space>and<seq2seq4repair_space>greater<seq2seq4repair_space>than<seq2seq4repair_space>2!" ) ) ; } FunctionTestSetup . addDoc ( iw , i ) ; done [ i ] = true ; i = ( i + 4 ) % ( FunctionTestSetup . N_DOCS ) ; remaining -- ; } if ( ! doMultiSegment ) { if ( VERBOSE ) { System . out . println ( "TEST:<seq2seq4repair_space>setUp<seq2seq4repair_space>full<seq2seq4repair_space>merge" ) ; } iw . forceMerge ( 1 ) ; } <START_BUG> iw . close ( ) ; <END_BUG> if ( VERBOSE ) { System . out . println ( "TEST:<seq2seq4repair_space>setUp<seq2seq4repair_space>done<seq2seq4repair_space>close" ) ; } } private static void addDoc ( RandomIndexWriter iw , int i ) throws Exception { } protected static String id2String ( int scoreAndID ) { } private static String textLine ( int docNum ) { } protected static float expectedFieldScore ( String docIDFieldVal ) { } protected static void log ( Object o ) { } }

Fix:
iw . shutdown ( ) ;