Buggy code:
public class TestSimilarity extends LuceneTestCase { public static class SimpleSimilarity extends DefaultSimilarity { @ Override public float queryNorm ( float sumOfSquaredWeights ) { } @ Override public float coord ( int overlap , int maxOverlap ) { } @ Override public float lengthNorm ( FieldInvertState state ) { } @ Override public float tf ( float freq ) { } @ Override public float sloppyFreq ( int distance ) { } @ Override public float idf ( long docFreq , long numDocs ) { } @ Override public Explanation idfExplain ( CollectionStatistics collectionStats , TermStatistics [ ] stats ) { } } public void testSimilarity ( ) throws Exception { Directory store = newDirectory ( ) ; RandomIndexWriter writer = new RandomIndexWriter ( random ( ) , store , newIndexWriterConfig ( TEST_VERSION_CURRENT , new org . apache . lucene . analysis . MockAnalyzer ( random ( ) ) ) . setSimilarity ( new TestSimilarity . SimpleSimilarity ( ) ) ) ; Document d1 = new Document ( ) ; d1 . add ( newTextField ( "field" , "a<seq2seq4repair_space>c" , YES ) ) ; Document d2 = new Document ( ) ; d2 . add ( newTextField ( "field" , "a<seq2seq4repair_space>b<seq2seq4repair_space>c" , YES ) ) ; writer . addDocument ( d1 ) ; writer . addDocument ( d2 ) ; IndexReader reader = writer . getReader ( ) ; <START_BUG> writer . close ( ) ; <END_BUG> IndexSearcher searcher = newSearcher ( reader ) ; searcher . setSimilarity ( new TestSimilarity . SimpleSimilarity ( ) ) ; Term a = new Term ( "field" , "a" ) ; Term b = new Term ( "field" , "b" ) ; Term c = new Term ( "field" , "c" ) ; searcher . search ( new TermQuery ( b ) , new SimpleCollector ( ) { private Scorer scorer ; @ Override public void setScorer ( Scorer scorer ) { this . scorer = scorer ; } @ Override public final void collect ( int doc ) throws IOException { assertEquals ( 1.0F , scorer . score ( ) , 0 ) ; } public boolean acceptsDocsOutOfOrder ( ) { return true ; } } ) ; BooleanQuery bq = new BooleanQuery ( ) ; bq . add ( new TermQuery ( a ) , SHOULD ) ; bq . add ( new TermQuery ( b ) , SHOULD ) ; searcher . search ( bq , new SimpleCollector ( ) { private int base = 0 ; private Scorer scorer ; @ Override public void setScorer ( Scorer scorer ) { this . scorer = scorer ; } @ Override public final void collect ( int doc ) throws IOException { assertEquals ( ( ( ( ( float ) ( doc ) ) + ( base ) ) + 1 ) , scorer . score ( ) , 0 ) ; } @ Override protected void doSetNextReader ( AtomicReaderContext context ) throws IOException { base = context . docBase ; } @ Override public boolean acceptsDocsOutOfOrder ( ) { return true ; } } ) ; PhraseQuery pq = new PhraseQuery ( ) ; pq . add ( a ) ; pq . add ( c ) ; searcher . search ( pq , new SimpleCollector ( ) { private Scorer scorer ; @ Override public void setScorer ( Scorer scorer ) { this . scorer = scorer ; } @ Override public final void collect ( int doc ) throws IOException { assertEquals ( 1.0F , scorer . score ( ) , 0 ) ; } @ Override public boolean acceptsDocsOutOfOrder ( ) { return true ; } } ) ; pq . setSlop ( 2 ) ; searcher . search ( pq , new SimpleCollector ( ) { private Scorer scorer ; @ Override public void setScorer ( Scorer scorer ) { this . scorer = scorer ; } @ Override public final void collect ( int doc ) throws IOException { assertEquals ( 2.0F , scorer . score ( ) , 0 ) ; } @ Override public boolean acceptsDocsOutOfOrder ( ) { return true ; } } ) ; reader . close ( ) ; store . close ( ) ; } }

Fix:
writer . shutdown ( ) ;