Buggy code:
@ SuppressCodecs ( { "Lucene40" , "Lucene41" } ) public class TestMinShouldMatch2 extends LuceneTestCase { static Directory dir ; static DirectoryReader r ; static AtomicReader reader ; static IndexSearcher searcher ; static final String [ ] alwaysTerms = new String [ ] { "a" } ; static final String [ ] commonTerms = new String [ ] { "b" , "c" , "d" } ; static final String [ ] mediumTerms = new String [ ] { "e" , "f" , "g" } ; static final String [ ] rareTerms = new String [ ] { "h" , "i" , "j" , "k" , "l" , "m" , "n" , "o" , "p" , "q" , "r" , "s" , "t" , "u" , "v" , "w" , "x" , "y" , "z" } ; @ BeforeClass public static void beforeClass ( ) throws Exception { TestMinShouldMatch2 . dir = newDirectory ( ) ; RandomIndexWriter iw = new RandomIndexWriter ( random ( ) , TestMinShouldMatch2 . dir ) ; final int numDocs = atLeast ( 300 ) ; for ( int i = 0 ; i < numDocs ; i ++ ) { Document doc = new Document ( ) ; TestMinShouldMatch2 . addSome ( doc , TestMinShouldMatch2 . alwaysTerms ) ; if ( ( random ( ) . nextInt ( 100 ) ) < 90 ) { TestMinShouldMatch2 . addSome ( doc , TestMinShouldMatch2 . commonTerms ) ; } if ( ( random ( ) . nextInt ( 100 ) ) < 50 ) { TestMinShouldMatch2 . addSome ( doc , TestMinShouldMatch2 . mediumTerms ) ; } if ( ( random ( ) . nextInt ( 100 ) ) < 10 ) { TestMinShouldMatch2 . addSome ( doc , TestMinShouldMatch2 . rareTerms ) ; } iw . addDocument ( doc ) ; } iw . forceMerge ( 1 ) ; <START_BUG> iw . close ( ) ; <END_BUG> TestMinShouldMatch2 . r = DirectoryReader . open ( TestMinShouldMatch2 . dir ) ; TestMinShouldMatch2 . reader = getOnlySegmentReader ( TestMinShouldMatch2 . r ) ; TestMinShouldMatch2 . searcher = new IndexSearcher ( TestMinShouldMatch2 . reader ) ; TestMinShouldMatch2 . searcher . setSimilarity ( new DefaultSimilarity ( ) { @ Override public float queryNorm ( float sumOfSquaredWeights ) { return 1 ; } } ) ; } @ AfterClass public static void afterClass ( ) throws Exception { } private static void addSome ( Document doc , String [ ] values ) { } private Scorer scorer ( String [ ] values , int minShouldMatch , boolean slow ) throws Exception { } private void assertNext ( Scorer expected , Scorer actual ) throws Exception { } private void assertAdvance ( Scorer expected , Scorer actual , int amount ) throws Exception { } public void testNextCMR2 ( ) throws Exception { } public void testAdvanceCMR2 ( ) throws Exception { } public void testNextAllTerms ( ) throws Exception { } public void testAdvanceAllTerms ( ) throws Exception { } public void testNextVaryingNumberOfTerms ( ) throws Exception { } public void testAdvanceVaryingNumberOfTerms ( ) throws Exception { } static class SlowMinShouldMatchScorer extends Scorer { int currentDoc = - 1 ; int currentMatched = - 1 ; final SortedSetDocValues dv ; final int maxDoc ; final Set < Long > ords = new HashSet < > ( ) ; final SimScorer [ ] sims ; final int minNrShouldMatch ; double score = Float . NaN ; SlowMinShouldMatchScorer ( BooleanWeight weight , AtomicReader reader , IndexSearcher searcher ) throws IOException { } @ Override public float score ( ) throws IOException { } @ Override public int freq ( ) throws IOException { } @ Override public int docID ( ) { } @ Override public int nextDoc ( ) throws IOException { } @ Override public int advance ( int target ) throws IOException { } @ Override public long cost ( ) { } } }

Fix:
iw . shutdown ( ) ;