Buggy code:
public class TestDocValuesScoring extends LuceneTestCase { private static final float SCORE_EPSILON = 0.001F ; public void testSimple ( ) throws Exception { Directory dir = newDirectory ( ) ; RandomIndexWriter iw = new RandomIndexWriter ( random ( ) , dir ) ; Document doc = new Document ( ) ; Field field = newTextField ( "foo" , "" , NO ) ; doc . add ( field ) ; Field dvField = new FloatDocValuesField ( "foo_boost" , 0.0F ) ; doc . add ( dvField ) ; Field field2 = newTextField ( "bar" , "" , NO ) ; doc . add ( field2 ) ; field . setStringValue ( "quick<seq2seq4repair_space>brown<seq2seq4repair_space>fox" ) ; field2 . setStringValue ( "quick<seq2seq4repair_space>brown<seq2seq4repair_space>fox" ) ; dvField . setFloatValue ( 2.0F ) ; iw . addDocument ( doc ) ; field . setStringValue ( "jumps<seq2seq4repair_space>over<seq2seq4repair_space>lazy<seq2seq4repair_space>brown<seq2seq4repair_space>dog" ) ; field2 . setStringValue ( "jumps<seq2seq4repair_space>over<seq2seq4repair_space>lazy<seq2seq4repair_space>brown<seq2seq4repair_space>dog" ) ; dvField . setFloatValue ( 4.0F ) ; iw . addDocument ( doc ) ; IndexReader ir = iw . getReader ( ) ; <START_BUG> iw . close ( ) ; <END_BUG> IndexSearcher searcher1 = newSearcher ( ir , false ) ; final Similarity base = searcher1 . getSimilarity ( ) ; IndexSearcher searcher2 = newSearcher ( ir , false ) ; searcher2 . setSimilarity ( new PerFieldSimilarityWrapper ( ) { final Similarity fooSim = new TestDocValuesScoring . BoostingSimilarity ( base , "foo_boost" ) ; @ Override public Similarity get ( String field ) { return "foo" . equals ( field ) ? fooSim : base ; } @ Override public float coord ( int overlap , int maxOverlap ) { return base . coord ( overlap , maxOverlap ) ; } @ Override public float queryNorm ( float sumOfSquaredWeights ) { return base . queryNorm ( sumOfSquaredWeights ) ; } } ) ; TermQuery tq = new TermQuery ( new Term ( "foo" , "quick" ) ) ; QueryUtils . check ( random ( ) , tq , searcher1 ) ; QueryUtils . check ( random ( ) , tq , searcher2 ) ; TopDocs noboost = searcher1 . search ( tq , 10 ) ; TopDocs boost = searcher2 . search ( tq , 10 ) ; assertEquals ( 1 , noboost . totalHits ) ; assertEquals ( 1 , boost . totalHits ) ; assertEquals ( boost . scoreDocs [ 0 ] . score , ( ( noboost . scoreDocs [ 0 ] . score ) * 2.0F ) , TestDocValuesScoring . SCORE_EPSILON ) ; tq = new TermQuery ( new Term ( "foo" , "jumps" ) ) ; QueryUtils . check ( random ( ) , tq , searcher1 ) ; QueryUtils . check ( random ( ) , tq , searcher2 ) ; noboost = searcher1 . search ( tq , 10 ) ; boost = searcher2 . search ( tq , 10 ) ; assertEquals ( 1 , noboost . totalHits ) ; assertEquals ( 1 , boost . totalHits ) ; assertEquals ( boost . scoreDocs [ 0 ] . score , ( ( noboost . scoreDocs [ 0 ] . score ) * 4.0F ) , TestDocValuesScoring . SCORE_EPSILON ) ; tq = new TermQuery ( new Term ( "bar" , "quick" ) ) ; QueryUtils . check ( random ( ) , tq , searcher1 ) ; QueryUtils . check ( random ( ) , tq , searcher2 ) ; noboost = searcher1 . search ( tq , 10 ) ; boost = searcher2 . search ( tq , 10 ) ; assertEquals ( 1 , noboost . totalHits ) ; assertEquals ( 1 , boost . totalHits ) ; assertEquals ( boost . scoreDocs [ 0 ] . score , noboost . scoreDocs [ 0 ] . score , TestDocValuesScoring . SCORE_EPSILON ) ; ir . close ( ) ; dir . close ( ) ; } static class BoostingSimilarity extends Similarity { private final Similarity sim ; private final String boostField ; public BoostingSimilarity ( Similarity sim , String boostField ) { } @ Override public long computeNorm ( FieldInvertState state ) { } @ Override public SimWeight computeWeight ( float queryBoost , CollectionStatistics collectionStats , TermStatistics ... termStats ) { } @ Override public SimScorer simScorer ( SimWeight stats , AtomicReaderContext context ) throws IOException { } } }

Fix:
iw . shutdown ( ) ;