Buggy code:
public class TestSpanQueryFilter extends LuceneTestCase { public void testFilterWorks ( ) throws Exception { Directory dir = newDirectory ( ) ; RandomIndexWriter writer = new RandomIndexWriter ( random , dir , newIndexWriterConfig ( TEST_VERSION_CURRENT , new org . apache . lucene . analysis . MockAnalyzer ( random ) ) . setMergePolicy ( newLogMergePolicy ( ) ) ) ; for ( int i = 0 ; i < 500 ; i ++ ) { Document document = new Document ( ) ; document . add ( newField ( "field" , ( ( ( English . intToEnglish ( i ) ) + "<seq2seq4repair_space>equals<seq2seq4repair_space>" ) + ( English . intToEnglish ( i ) ) ) , TYPE_UNSTORED ) ) ; writer . addDocument ( document ) ; } final int number = 10 ; IndexReader reader = writer . getReader ( ) ; writer . close ( ) ; AtomicReaderContext [ ] leaves = ReaderUtil . leaves ( reader . getTopReaderContext ( ) ) ; int subIndex = ReaderUtil . subIndex ( number , leaves ) ; SpanTermQuery query = new SpanTermQuery ( new org . apache . lucene . index . Term ( "field" , English . intToEnglish ( number ) . trim ( ) ) ) ; SpanQueryFilter filter = new SpanQueryFilter ( query ) ; <START_BUG> SpanFilterResult result = filter . bitSpans ( leaves [ subIndex ] ) ; <END_BUG> DocIdSet docIdSet = result . getDocIdSet ( ) ; assertTrue ( "docIdSet<seq2seq4repair_space>is<seq2seq4repair_space>null<seq2seq4repair_space>and<seq2seq4repair_space>it<seq2seq4repair_space>shouldn't<seq2seq4repair_space>be" , ( docIdSet != null ) ) ; assertContainsDocId ( "docIdSet<seq2seq4repair_space>doesn't<seq2seq4repair_space>contain<seq2seq4repair_space>docId<seq2seq4repair_space>10" , docIdSet , ( number - ( leaves [ subIndex ] . docBase ) ) ) ; List < SpanFilterResult . PositionInfo > spans = result . getPositions ( ) ; assertTrue ( "spans<seq2seq4repair_space>is<seq2seq4repair_space>null<seq2seq4repair_space>and<seq2seq4repair_space>it<seq2seq4repair_space>shouldn't<seq2seq4repair_space>be" , ( spans != null ) ) ; int size = getDocIdSetSize ( docIdSet ) ; assertTrue ( ( ( ( "spans<seq2seq4repair_space>Size:<seq2seq4repair_space>" + ( spans . size ( ) ) ) + "<seq2seq4repair_space>is<seq2seq4repair_space>not:<seq2seq4repair_space>" ) + size ) , ( ( spans . size ( ) ) == size ) ) ; for ( final SpanFilterResult . PositionInfo info : spans ) { assertTrue ( "info<seq2seq4repair_space>is<seq2seq4repair_space>null<seq2seq4repair_space>and<seq2seq4repair_space>it<seq2seq4repair_space>shouldn't<seq2seq4repair_space>be" , ( info != null ) ) ; assertContainsDocId ( ( "docIdSet<seq2seq4repair_space>doesn't<seq2seq4repair_space>contain<seq2seq4repair_space>docId<seq2seq4repair_space>" + ( info . getDoc ( ) ) ) , docIdSet , info . getDoc ( ) ) ; assertTrue ( ( ( ( "info.getPositions()<seq2seq4repair_space>Size:<seq2seq4repair_space>" + ( info . getPositions ( ) . size ( ) ) ) + "<seq2seq4repair_space>is<seq2seq4repair_space>not:<seq2seq4repair_space>" ) + 2 ) , ( ( info . getPositions ( ) . size ( ) ) == 2 ) ) ; } reader . close ( ) ; dir . close ( ) ; } int getDocIdSetSize ( DocIdSet docIdSet ) throws Exception { } public void assertContainsDocId ( String msg , DocIdSet docIdSet , int docId ) throws Exception { } }

Fix:
SpanFilterResult result = filter . bitSpans ( leaves [ subIndex ] , leaves [ subIndex ] . reader . getLiveDocs ( ) ) ;