Buggy code:
public class TestPayloadNearQuery extends LuceneTestCase { private static IndexSearcher searcher ; private static IndexReader reader ; private static Directory directory ; private static TestPayloadNearQuery . BoostingSimilarity similarity = new TestPayloadNearQuery . BoostingSimilarity ( ) ; private static byte [ ] payload2 = new byte [ ] { 2 } ; private static byte [ ] payload4 = new byte [ ] { 4 } ; private static class PayloadAnalyzer extends Analyzer { @ Override public TokenStreamComponents createComponents ( String fieldName ) { } } private static class PayloadFilter extends TokenFilter { private final String fieldName ; private int numSeen = 0 ; private final PayloadAttribute payAtt ; public PayloadFilter ( TokenStream input , String fieldName ) { } @ Override public boolean incrementToken ( ) throws IOException { } @ Override public void reset ( ) throws IOException { } } private PayloadNearQuery newPhraseQuery ( String fieldName , String phrase , boolean inOrder , PayloadFunction function ) { } @ BeforeClass public static void beforeClass ( ) throws Exception { TestPayloadNearQuery . directory = newDirectory ( ) ; RandomIndexWriter writer = new RandomIndexWriter ( random ( ) , TestPayloadNearQuery . directory , newIndexWriterConfig ( TEST_VERSION_CURRENT , new TestPayloadNearQuery . PayloadAnalyzer ( ) ) . setSimilarity ( TestPayloadNearQuery . similarity ) ) ; for ( int i = 0 ; i < 1000 ; i ++ ) { Document doc = new Document ( ) ; doc . add ( newTextField ( "field" , English . intToEnglish ( i ) , YES ) ) ; String txt = ( ( English . intToEnglish ( i ) ) + '<seq2seq4repair_space>' ) + ( English . intToEnglish ( ( i + 1 ) ) ) ; doc . add ( newTextField ( "field2" , txt , YES ) ) ; writer . addDocument ( doc ) ; } TestPayloadNearQuery . reader = writer . getReader ( ) ; <START_BUG> writer . close ( ) ; <END_BUG> TestPayloadNearQuery . searcher = newSearcher ( TestPayloadNearQuery . reader ) ; TestPayloadNearQuery . searcher . setSimilarity ( TestPayloadNearQuery . similarity ) ; } @ AfterClass public static void afterClass ( ) throws Exception { } public void test ( ) throws IOException { } public void testPayloadNear ( ) throws IOException { } public void testAverageFunction ( ) throws IOException { } public void testMaxFunction ( ) throws IOException { } public void testMinFunction ( ) throws IOException { } private SpanQuery [ ] getClauses ( ) { } private SpanNearQuery spanNearQuery ( String fieldName , String words ) { } public void testLongerSpan ( ) throws IOException { } public void testComplexNested ( ) throws IOException { } 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 tf ( float freq ) { } @ Override public Explanation idfExplain ( CollectionStatistics collectionStats , TermStatistics [ ] termStats ) { } } }

Fix:
writer . shutdown ( ) ;