Buggy code:
public class TestSimilarityBase extends LuceneTestCase { private static String FIELD_BODY = "body" ; private static String FIELD_ID = "id" ; private static float FLOAT_EPSILON = 1.0E-5F ; static BasicModel [ ] BASIC_MODELS = new BasicModel [ ] { new BasicModelBE ( ) , new BasicModelD ( ) , new BasicModelG ( ) , new BasicModelIF ( ) , new BasicModelIn ( ) , new BasicModelIne ( ) , new BasicModelP ( ) } ; static AfterEffect [ ] AFTER_EFFECTS = new AfterEffect [ ] { new AfterEffectB ( ) , new AfterEffectL ( ) , new AfterEffect . NoAfterEffect ( ) } ; static Normalization [ ] NORMALIZATIONS = new Normalization [ ] { new NormalizationH1 ( ) , new NormalizationH2 ( ) , new NormalizationH3 ( ) , new NormalizationZ ( ) , new Normalization . NoNormalization ( ) } ; static Distribution [ ] DISTRIBUTIONS = new Distribution [ ] { new DistributionLL ( ) , new DistributionSPL ( ) } ; static Lambda [ ] LAMBDAS = new Lambda [ ] { new LambdaDF ( ) , new LambdaTTF ( ) } ; private IndexSearcher searcher ; private Directory dir ; private IndexReader reader ; private List < SimilarityBase > sims ; @ Override public void setUp ( ) throws Exception { super . setUp ( ) ; dir = newDirectory ( ) ; RandomIndexWriter writer = new RandomIndexWriter ( random ( ) , dir ) ; for ( int i = 0 ; i < ( docs . length ) ; i ++ ) { Document d = new Document ( ) ; FieldType ft = new FieldType ( TextField . TYPE_STORED ) ; ft . setIndexed ( false ) ; d . add ( newField ( TestSimilarityBase . FIELD_ID , Integer . toString ( i ) , ft ) ) ; d . add ( newTextField ( TestSimilarityBase . FIELD_BODY , docs [ i ] , YES ) ) ; writer . addDocument ( d ) ; } reader = writer . getReader ( ) ; searcher = newSearcher ( reader ) ; <START_BUG> writer . close ( ) ; <END_BUG> sims = new ArrayList ( ) ; for ( BasicModel basicModel : TestSimilarityBase . BASIC_MODELS ) { for ( AfterEffect afterEffect : TestSimilarityBase . AFTER_EFFECTS ) { for ( Normalization normalization : TestSimilarityBase . NORMALIZATIONS ) { sims . add ( new DFRSimilarity ( basicModel , afterEffect , normalization ) ) ; } } } for ( Distribution distribution : TestSimilarityBase . DISTRIBUTIONS ) { for ( Lambda lambda : TestSimilarityBase . LAMBDAS ) { for ( Normalization normalization : TestSimilarityBase . NORMALIZATIONS ) { sims . add ( new IBSimilarity ( distribution , lambda , normalization ) ) ; } } } sims . add ( new LMDirichletSimilarity ( ) ) ; sims . add ( new LMJelinekMercerSimilarity ( 0.1F ) ) ; sims . add ( new LMJelinekMercerSimilarity ( 0.7F ) ) ; } private static int NUMBER_OF_DOCUMENTS = 100 ; private static long NUMBER_OF_FIELD_TOKENS = 5000 ; private static float AVG_FIELD_LENGTH = 50 ; private static int DOC_FREQ = 10 ; private static long TOTAL_TERM_FREQ = 70 ; private static float FREQ = 7 ; private static int DOC_LEN = 40 ; private BasicStats createStats ( ) { } private CollectionStatistics toCollectionStats ( BasicStats stats ) { } private TermStatistics toTermStats ( BasicStats stats ) { } private void unitTestCore ( BasicStats stats , float freq , int docLen ) { } public void testDefault ( ) throws IOException { } public void testSparseDocuments ( ) throws IOException { } public void testVerySparseDocuments ( ) throws IOException { } public void testOneDocument ( ) throws IOException { } public void testAllDocumentsRelevant ( ) throws IOException { } public void testMostDocumentsRelevant ( ) throws IOException { } public void testOnlyOneRelevantDocument ( ) throws IOException { } public void testAllTermsRelevant ( ) throws IOException { } public void testMoreTermsThanDocuments ( ) throws IOException { } public void testNumberOfTermsAsDocuments ( ) throws IOException { } public void testOneTerm ( ) throws IOException { } public void testOneRelevantDocument ( ) throws IOException { } public void testAllTermsRelevantOnlyOneDocument ( ) throws IOException { } public void testOnlyOneTermOneDocument ( ) throws IOException { } public void testOnlyOneTerm ( ) throws IOException { } public void testDocumentLengthAverage ( ) throws IOException { } public void testLMDirichlet ( ) throws IOException { } public void testLMJelinekMercer ( ) throws IOException { } public void testLLForIB ( ) throws IOException { } public void testSPLForIB ( ) throws IOException { } public void testPL2 ( ) throws IOException { } public void testIneB2 ( ) throws IOException { } public void testGL1 ( ) throws IOException { } public void testBEB1 ( ) throws IOException { } public void testD ( ) throws IOException { } public void testIn2 ( ) throws IOException { } public void testIFB ( ) throws IOException { } private void correctnessTestCore ( SimilarityBase sim , float gold ) { } String [ ] docs = new String [ ] { "Tiger,<seq2seq4repair_space>tiger<seq2seq4repair_space>burning<seq2seq4repair_space>bright<seq2seq4repair_space>In<seq2seq4repair_space>the<seq2seq4repair_space>forest<seq2seq4repair_space>of<seq2seq4repair_space>the<seq2seq4repair_space>night<seq2seq4repair_space>What<seq2seq4repair_space>immortal<seq2seq4repair_space>hand<seq2seq4repair_space>or<seq2seq4repair_space>eye<seq2seq4repair_space>Could<seq2seq4repair_space>frame<seq2seq4repair_space>thy<seq2seq4repair_space>fearful<seq2seq4repair_space>symmetry<seq2seq4repair_space>?" , "In<seq2seq4repair_space>what<seq2seq4repair_space>distant<seq2seq4repair_space>depths<seq2seq4repair_space>or<seq2seq4repair_space>skies<seq2seq4repair_space>Burnt<seq2seq4repair_space>the<seq2seq4repair_space>fire<seq2seq4repair_space>of<seq2seq4repair_space>thine<seq2seq4repair_space>eyes<seq2seq4repair_space>?<seq2seq4repair_space>On<seq2seq4repair_space>what<seq2seq4repair_space>wings<seq2seq4repair_space>dare<seq2seq4repair_space>he<seq2seq4repair_space>aspire<seq2seq4repair_space>?<seq2seq4repair_space>What<seq2seq4repair_space>the<seq2seq4repair_space>hands<seq2seq4repair_space>the<seq2seq4repair_space>seize<seq2seq4repair_space>the<seq2seq4repair_space>fire<seq2seq4repair_space>?" , "And<seq2seq4repair_space>what<seq2seq4repair_space>shoulder<seq2seq4repair_space>and<seq2seq4repair_space>what<seq2seq4repair_space>art<seq2seq4repair_space>Could<seq2seq4repair_space>twist<seq2seq4repair_space>the<seq2seq4repair_space>sinews<seq2seq4repair_space>of<seq2seq4repair_space>thy<seq2seq4repair_space>heart<seq2seq4repair_space>?<seq2seq4repair_space>And<seq2seq4repair_space>when<seq2seq4repair_space>thy<seq2seq4repair_space>heart<seq2seq4repair_space>began<seq2seq4repair_space>to<seq2seq4repair_space>beat<seq2seq4repair_space>What<seq2seq4repair_space>dread<seq2seq4repair_space>hand<seq2seq4repair_space>?<seq2seq4repair_space>And<seq2seq4repair_space>what<seq2seq4repair_space>dread<seq2seq4repair_space>feet<seq2seq4repair_space>?" , "What<seq2seq4repair_space>the<seq2seq4repair_space>hammer?<seq2seq4repair_space>What<seq2seq4repair_space>the<seq2seq4repair_space>chain<seq2seq4repair_space>?<seq2seq4repair_space>In<seq2seq4repair_space>what<seq2seq4repair_space>furnace<seq2seq4repair_space>was<seq2seq4repair_space>thy<seq2seq4repair_space>brain<seq2seq4repair_space>?<seq2seq4repair_space>What<seq2seq4repair_space>the<seq2seq4repair_space>anvil<seq2seq4repair_space>?<seq2seq4repair_space>And<seq2seq4repair_space>what<seq2seq4repair_space>dread<seq2seq4repair_space>grasp<seq2seq4repair_space>Dare<seq2seq4repair_space>its<seq2seq4repair_space>deadly<seq2seq4repair_space>terrors<seq2seq4repair_space>clasp<seq2seq4repair_space>?" , "And<seq2seq4repair_space>when<seq2seq4repair_space>the<seq2seq4repair_space>stars<seq2seq4repair_space>threw<seq2seq4repair_space>down<seq2seq4repair_space>their<seq2seq4repair_space>spears<seq2seq4repair_space>And<seq2seq4repair_space>water'd<seq2seq4repair_space>heaven<seq2seq4repair_space>with<seq2seq4repair_space>their<seq2seq4repair_space>tear<seq2seq4repair_space>Did<seq2seq4repair_space>he<seq2seq4repair_space>smile<seq2seq4repair_space>his<seq2seq4repair_space>work<seq2seq4repair_space>to<seq2seq4repair_space>see<seq2seq4repair_space>?<seq2seq4repair_space>Did<seq2seq4repair_space>he,<seq2seq4repair_space>who<seq2seq4repair_space>made<seq2seq4repair_space>the<seq2seq4repair_space>lamb,<seq2seq4repair_space>made<seq2seq4repair_space>thee<seq2seq4repair_space>?" , "Tiger,<seq2seq4repair_space>tiger<seq2seq4repair_space>burning<seq2seq4repair_space>bright<seq2seq4repair_space>In<seq2seq4repair_space>the<seq2seq4repair_space>forest<seq2seq4repair_space>of<seq2seq4repair_space>the<seq2seq4repair_space>night<seq2seq4repair_space>What<seq2seq4repair_space>immortal<seq2seq4repair_space>hand<seq2seq4repair_space>or<seq2seq4repair_space>eye<seq2seq4repair_space>Dare<seq2seq4repair_space>frame<seq2seq4repair_space>thy<seq2seq4repair_space>fearful<seq2seq4repair_space>symmetry<seq2seq4repair_space>?" , "Cruelty<seq2seq4repair_space>has<seq2seq4repair_space>a<seq2seq4repair_space>human<seq2seq4repair_space>heart<seq2seq4repair_space>And<seq2seq4repair_space>jealousy<seq2seq4repair_space>a<seq2seq4repair_space>human<seq2seq4repair_space>face<seq2seq4repair_space>Terror<seq2seq4repair_space>the<seq2seq4repair_space>human<seq2seq4repair_space>form<seq2seq4repair_space>divine<seq2seq4repair_space>And<seq2seq4repair_space>Secrecy<seq2seq4repair_space>the<seq2seq4repair_space>human<seq2seq4repair_space>dress<seq2seq4repair_space>." , "The<seq2seq4repair_space>human<seq2seq4repair_space>dress<seq2seq4repair_space>is<seq2seq4repair_space>forg'd<seq2seq4repair_space>iron<seq2seq4repair_space>The<seq2seq4repair_space>human<seq2seq4repair_space>form<seq2seq4repair_space>a<seq2seq4repair_space>fiery<seq2seq4repair_space>forge<seq2seq4repair_space>The<seq2seq4repair_space>human<seq2seq4repair_space>face<seq2seq4repair_space>a<seq2seq4repair_space>furnace<seq2seq4repair_space>seal'd<seq2seq4repair_space>The<seq2seq4repair_space>human<seq2seq4repair_space>heart<seq2seq4repair_space>its<seq2seq4repair_space>fiery<seq2seq4repair_space>gorge<seq2seq4repair_space>." } ; public void testHeartList ( ) throws IOException { } public void testHeartRanking ( ) throws IOException { } @ Override public void tearDown ( ) throws Exception { } public void testDiscountOverlapsBoost ( ) throws IOException { } }

Fix:
writer . shutdown ( ) ;