Buggy code:
public class TestSloppyPhraseQuery extends LuceneTestCase { private static final String S_1 = "A<seq2seq4repair_space>A<seq2seq4repair_space>A" ; private static final String S_2 = "A<seq2seq4repair_space>1<seq2seq4repair_space>2<seq2seq4repair_space>3<seq2seq4repair_space>A<seq2seq4repair_space>4<seq2seq4repair_space>5<seq2seq4repair_space>6<seq2seq4repair_space>A" ; private static final Document DOC_1 = TestSloppyPhraseQuery . makeDocument ( ( ( "X<seq2seq4repair_space>" + ( TestSloppyPhraseQuery . S_1 ) ) + "<seq2seq4repair_space>Y" ) ) ; private static final Document DOC_2 = TestSloppyPhraseQuery . makeDocument ( ( ( "X<seq2seq4repair_space>" + ( TestSloppyPhraseQuery . S_2 ) ) + "<seq2seq4repair_space>Y" ) ) ; private static final Document DOC_3 = TestSloppyPhraseQuery . makeDocument ( ( ( "X<seq2seq4repair_space>" + ( TestSloppyPhraseQuery . S_1 ) ) + "<seq2seq4repair_space>A<seq2seq4repair_space>Y" ) ) ; private static final Document DOC_1_B = TestSloppyPhraseQuery . makeDocument ( ( ( ( ( "X<seq2seq4repair_space>" + ( TestSloppyPhraseQuery . S_1 ) ) + "<seq2seq4repair_space>Y<seq2seq4repair_space>N<seq2seq4repair_space>N<seq2seq4repair_space>N<seq2seq4repair_space>N<seq2seq4repair_space>" ) + ( TestSloppyPhraseQuery . S_1 ) ) + "<seq2seq4repair_space>Z" ) ) ; private static final Document DOC_2_B = TestSloppyPhraseQuery . makeDocument ( ( ( ( ( "X<seq2seq4repair_space>" + ( TestSloppyPhraseQuery . S_2 ) ) + "<seq2seq4repair_space>Y<seq2seq4repair_space>N<seq2seq4repair_space>N<seq2seq4repair_space>N<seq2seq4repair_space>N<seq2seq4repair_space>" ) + ( TestSloppyPhraseQuery . S_2 ) ) + "<seq2seq4repair_space>Z" ) ) ; private static final Document DOC_3_B = TestSloppyPhraseQuery . makeDocument ( ( ( ( ( "X<seq2seq4repair_space>" + ( TestSloppyPhraseQuery . S_1 ) ) + "<seq2seq4repair_space>A<seq2seq4repair_space>Y<seq2seq4repair_space>N<seq2seq4repair_space>N<seq2seq4repair_space>N<seq2seq4repair_space>N<seq2seq4repair_space>" ) + ( TestSloppyPhraseQuery . S_1 ) ) + "<seq2seq4repair_space>A<seq2seq4repair_space>Y" ) ) ; private static final Document DOC_4 = TestSloppyPhraseQuery . makeDocument ( "A<seq2seq4repair_space>A<seq2seq4repair_space>X<seq2seq4repair_space>A<seq2seq4repair_space>X<seq2seq4repair_space>B<seq2seq4repair_space>A<seq2seq4repair_space>X<seq2seq4repair_space>B<seq2seq4repair_space>B<seq2seq4repair_space>A<seq2seq4repair_space>A<seq2seq4repair_space>X<seq2seq4repair_space>B<seq2seq4repair_space>A<seq2seq4repair_space>A" ) ; private static final PhraseQuery QUERY_1 = TestSloppyPhraseQuery . makePhraseQuery ( TestSloppyPhraseQuery . S_1 ) ; private static final PhraseQuery QUERY_2 = TestSloppyPhraseQuery . makePhraseQuery ( TestSloppyPhraseQuery . S_2 ) ; private static final PhraseQuery QUERY_4 = TestSloppyPhraseQuery . makePhraseQuery ( "X<seq2seq4repair_space>A<seq2seq4repair_space>A" ) ; public void testDoc4_Query4_All_Slops_Should_match ( ) throws Exception { } public void testDoc1_Query1_All_Slops_Should_match ( ) throws Exception { } public void testDoc2_Query1_Slop_6_or_more_Should_match ( ) throws Exception { } public void testDoc2_Query2_All_Slops_Should_match ( ) throws Exception { } public void testDoc3_Query1_All_Slops_Should_match ( ) throws Exception { } private float checkPhraseQuery ( Document doc , PhraseQuery query , int slop , int expectedNumResults ) throws Exception { query . setSlop ( slop ) ; RAMDirectory ramDir = new RAMDirectory ( ) ; WhitespaceAnalyzer analyzer = new WhitespaceAnalyzer ( ) ; IndexWriter writer = new IndexWriter ( ramDir , analyzer , MaxFieldLength . UNLIMITED ) ; writer . addDocument ( doc ) ; writer . close ( ) ; <START_BUG> IndexSearcher searcher = new IndexSearcher ( ramDir ) ; <END_BUG> TopDocs td = searcher . search ( query , null , 10 ) ; assertEquals ( ( ( ( ( ( ( "slop:<seq2seq4repair_space>" + slop ) + "<seq2seq4repair_space>query:<seq2seq4repair_space>" ) + query ) + "<seq2seq4repair_space>doc:<seq2seq4repair_space>" ) + doc ) + "<seq2seq4repair_space>Wrong<seq2seq4repair_space>number<seq2seq4repair_space>of<seq2seq4repair_space>hits" ) , expectedNumResults , td . totalHits ) ; searcher . close ( ) ; ramDir . close ( ) ; return td . getMaxScore ( ) ; } private static Document makeDocument ( String docText ) { } private static PhraseQuery makePhraseQuery ( String terms ) { } }

Fix:
IndexSearcher searcher = new IndexSearcher ( ramDir , true ) ;