Buggy code:
public class TestPayloadTermQuery extends LuceneTestCase { private static IndexSearcher searcher ; private static IndexReader reader ; private static Similarity similarity = new TestPayloadTermQuery . BoostingSimilarity ( ) ; private static final byte [ ] payloadField = new byte [ ] { 1 } ; private static final byte [ ] payloadMultiField1 = new byte [ ] { 2 } ; private static final byte [ ] payloadMultiField2 = new byte [ ] { 4 } ; protected static Directory directory ; private static class PayloadAnalyzer extends Analyzer { private PayloadAnalyzer ( ) { } @ Override public TokenStreamComponents createComponents ( String fieldName ) { } } private static class PayloadFilter extends TokenFilter { private final String fieldName ; private int numSeen = 0 ; private final PayloadAttribute payloadAtt ; public PayloadFilter ( TokenStream input , String fieldName ) { } @ Override public boolean incrementToken ( ) throws IOException { } @ Override public void reset ( ) throws IOException { } } @ BeforeClass public static void beforeClass ( ) throws Exception { TestPayloadTermQuery . directory = newDirectory ( ) ; RandomIndexWriter writer = new RandomIndexWriter ( random ( ) , TestPayloadTermQuery . directory , newIndexWriterConfig ( TEST_VERSION_CURRENT , new TestPayloadTermQuery . PayloadAnalyzer ( ) ) . setSimilarity ( TestPayloadTermQuery . similarity ) . setMergePolicy ( newLogMergePolicy ( ) ) ) ; for ( int i = 0 ; i < 1000 ; i ++ ) { Document doc = new Document ( ) ; Field noPayloadField = newTextField ( NO_PAYLOAD_FIELD , English . intToEnglish ( i ) , YES ) ; doc . add ( noPayloadField ) ; doc . add ( newTextField ( "field" , English . intToEnglish ( i ) , YES ) ) ; doc . add ( newTextField ( "multiField" , ( ( ( English . intToEnglish ( i ) ) + "<seq2seq4repair_space>" ) + ( English . intToEnglish ( i ) ) ) , YES ) ) ; writer . addDocument ( doc ) ; } TestPayloadTermQuery . reader = writer . getReader ( ) ; <START_BUG> writer . close ( ) ; <END_BUG> TestPayloadTermQuery . searcher = newSearcher ( TestPayloadTermQuery . reader ) ; TestPayloadTermQuery . searcher . setSimilarity ( TestPayloadTermQuery . similarity ) ; } @ AfterClass public static void afterClass ( ) throws Exception { } public void test ( ) throws IOException { } public void testQuery ( ) { } public void testMultipleMatchesPerDoc ( ) throws Exception { } public void testIgnoreSpanScorer ( ) throws Exception { } public void testNoMatch ( ) throws Exception { } public void testNoPayload ( ) throws Exception { } static class BoostingSimilarity extends DefaultSimilarity { @ Override public float queryNorm ( float sumOfSquaredWeights ) { } @ Override public float coord ( int overlap , int maxOverlap ) { } @ Override public float scorePayload ( int docId , int start , int end , BytesRef payload ) { } @ Override public float lengthNorm ( FieldInvertState state ) { } @ Override public float sloppyFreq ( int distance ) { } @ Override public float idf ( long docFreq , long numDocs ) { } @ Override public float tf ( float freq ) { } } static class FullSimilarity extends DefaultSimilarity { public float scorePayload ( int docId , String fieldName , byte [ ] payload , int offset , int length ) { } } }

Fix:
writer . shutdown ( ) ;