Buggy code:
public class TestFieldMaskingSpanQuery extends LuceneTestCase { protected static Document doc ( Field [ ] fields ) { } protected static Field field ( String name , String value ) { } protected IndexSearcher searcher ; public void setUp ( ) throws Exception { super . setUp ( ) ; RAMDirectory directory = new RAMDirectory ( ) ; IndexWriter writer = new IndexWriter ( directory , new WhitespaceAnalyzer ( ) , true , MaxFieldLength . LIMITED ) ; 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" ) } ) ) ; writer . close ( ) ; <START_BUG> searcher = new IndexSearcher ( directory ) ; <END_BUG> } public void tearDown ( ) 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:
searcher = new IndexSearcher ( directory , true ) ;