Buggy code:
public class TestFieldMaskingSpanQuery extends LuceneTestCase { protected static Document doc ( Field [ ] fields ) { } protected static Field field ( String name , String value ) { } protected static IndexSearcher searcher ; protected static Directory directory ; protected static IndexReader reader ; @ BeforeClass public static void beforeClass ( ) throws Exception { TestFieldMaskingSpanQuery . directory = newDirectory ( ) ; RandomIndexWriter writer = new RandomIndexWriter ( random ( ) , TestFieldMaskingSpanQuery . directory , newIndexWriterConfig ( TEST_VERSION_CURRENT , new org . apache . lucene . analysis . MockAnalyzer ( random ( ) ) ) . setMergePolicy ( newLogMergePolicy ( ) ) ) ; writer . addDocument ( TestFieldMaskingSpanQuery . doc ( new Field [ ] { TestFieldMaskingSpanQuery . field ( "id" , "0" ) , TestFieldMaskingSpanQuery . field ( "gender" , "male" ) , TestFieldMaskingSpanQuery . field ( "first" , "james" ) , TestFieldMaskingSpanQuery . field ( "last" , "jones" ) } ) ) ; writer . addDocument ( TestFieldMaskingSpanQuery . doc ( new Field [ ] { TestFieldMaskingSpanQuery . field ( "id" , "1" ) , TestFieldMaskingSpanQuery . field ( "gender" , "male" ) , TestFieldMaskingSpanQuery . field ( "first" , "james" ) , TestFieldMaskingSpanQuery . field ( "last" , "smith" ) , TestFieldMaskingSpanQuery . field ( "gender" , "female" ) , TestFieldMaskingSpanQuery . field ( "first" , "sally" ) , TestFieldMaskingSpanQuery . field ( "last" , "jones" ) } ) ) ; writer . addDocument ( TestFieldMaskingSpanQuery . doc ( new Field [ ] { TestFieldMaskingSpanQuery . field ( "id" , "2" ) , TestFieldMaskingSpanQuery . field ( "gender" , "female" ) , TestFieldMaskingSpanQuery . field ( "first" , "greta" ) , TestFieldMaskingSpanQuery . field ( "last" , "jones" ) , TestFieldMaskingSpanQuery . field ( "gender" , "female" ) , TestFieldMaskingSpanQuery . field ( "first" , "sally" ) , TestFieldMaskingSpanQuery . field ( "last" , "smith" ) , TestFieldMaskingSpanQuery . field ( "gender" , "male" ) , TestFieldMaskingSpanQuery . field ( "first" , "james" ) , TestFieldMaskingSpanQuery . field ( "last" , "jones" ) } ) ) ; writer . addDocument ( TestFieldMaskingSpanQuery . doc ( new Field [ ] { TestFieldMaskingSpanQuery . field ( "id" , "3" ) , TestFieldMaskingSpanQuery . field ( "gender" , "female" ) , TestFieldMaskingSpanQuery . field ( "first" , "lisa" ) , TestFieldMaskingSpanQuery . field ( "last" , "jones" ) , TestFieldMaskingSpanQuery . field ( "gender" , "male" ) , TestFieldMaskingSpanQuery . field ( "first" , "bob" ) , TestFieldMaskingSpanQuery . field ( "last" , "costas" ) } ) ) ; writer . addDocument ( TestFieldMaskingSpanQuery . doc ( new Field [ ] { TestFieldMaskingSpanQuery . field ( "id" , "4" ) , TestFieldMaskingSpanQuery . field ( "gender" , "female" ) , TestFieldMaskingSpanQuery . field ( "first" , "sally" ) , TestFieldMaskingSpanQuery . field ( "last" , "smith" ) , TestFieldMaskingSpanQuery . field ( "gender" , "female" ) , TestFieldMaskingSpanQuery . field ( "first" , "linda" ) , TestFieldMaskingSpanQuery . field ( "last" , "dixit" ) , TestFieldMaskingSpanQuery . field ( "gender" , "male" ) , TestFieldMaskingSpanQuery . field ( "first" , "bubba" ) , TestFieldMaskingSpanQuery . field ( "last" , "jones" ) } ) ) ; TestFieldMaskingSpanQuery . reader = writer . getReader ( ) ; <START_BUG> writer . close ( ) ; <END_BUG> TestFieldMaskingSpanQuery . searcher = newSearcher ( TestFieldMaskingSpanQuery . reader ) ; } @ AfterClass public static void afterClass ( ) throws Exception { } protected void check ( SpanQuery q , int [ ] docs ) throws Exception { } public void testRewrite0 ( ) throws Exception { } public void testRewrite1 ( ) throws Exception { } public void testRewrite2 ( ) throws Exception { } public void testEquality1 ( ) { } public void testNoop0 ( ) throws Exception { } public void testNoop1 ( ) throws Exception { } public void testSimple1 ( ) throws Exception { } public void testSimple2 ( ) throws Exception { } public void testSpans0 ( ) throws Exception { } public void testSpans1 ( ) throws Exception { } public void testSpans2 ( ) throws Exception { } public String s ( Spans span ) { } public String s ( int doc , int start , int end ) { } }

Fix:
writer . shutdown ( ) ;