Buggy code:
public class HighlighterTest extends TestCase implements Formatter { private IndexReader reader ; private static final String FIELD_NAME = "contents" ; private Query query ; RAMDirectory ramDir ; public Searcher searcher = null ; public Hits hits = null ; int numHighlights = 0 ; Analyzer analyzer = new StandardAnalyzer ( ) ; String [ ] texts = new String [ ] { "Hello<seq2seq4repair_space>this<seq2seq4repair_space>is<seq2seq4repair_space>a<seq2seq4repair_space>piece<seq2seq4repair_space>of<seq2seq4repair_space>text<seq2seq4repair_space>that<seq2seq4repair_space>is<seq2seq4repair_space>very<seq2seq4repair_space>long<seq2seq4repair_space>and<seq2seq4repair_space>contains<seq2seq4repair_space>too<seq2seq4repair_space>much<seq2seq4repair_space>preamble<seq2seq4repair_space>and<seq2seq4repair_space>the<seq2seq4repair_space>meat<seq2seq4repair_space>is<seq2seq4repair_space>really<seq2seq4repair_space>here<seq2seq4repair_space>which<seq2seq4repair_space>says<seq2seq4repair_space>kennedy<seq2seq4repair_space>has<seq2seq4repair_space>been<seq2seq4repair_space>shot" , "This<seq2seq4repair_space>piece<seq2seq4repair_space>of<seq2seq4repair_space>text<seq2seq4repair_space>refers<seq2seq4repair_space>to<seq2seq4repair_space>Kennedy<seq2seq4repair_space>at<seq2seq4repair_space>the<seq2seq4repair_space>beginning<seq2seq4repair_space>then<seq2seq4repair_space>has<seq2seq4repair_space>a<seq2seq4repair_space>longer<seq2seq4repair_space>piece<seq2seq4repair_space>of<seq2seq4repair_space>text<seq2seq4repair_space>that<seq2seq4repair_space>is<seq2seq4repair_space>very<seq2seq4repair_space>long<seq2seq4repair_space>in<seq2seq4repair_space>the<seq2seq4repair_space>middle<seq2seq4repair_space>and<seq2seq4repair_space>finally<seq2seq4repair_space>ends<seq2seq4repair_space>with<seq2seq4repair_space>another<seq2seq4repair_space>reference<seq2seq4repair_space>to<seq2seq4repair_space>Kennedy" , "JFK<seq2seq4repair_space>has<seq2seq4repair_space>been<seq2seq4repair_space>shot" , "John<seq2seq4repair_space>Kennedy<seq2seq4repair_space>has<seq2seq4repair_space>been<seq2seq4repair_space>shot" , "This<seq2seq4repair_space>text<seq2seq4repair_space>has<seq2seq4repair_space>a<seq2seq4repair_space>typo<seq2seq4repair_space>in<seq2seq4repair_space>referring<seq2seq4repair_space>to<seq2seq4repair_space>Keneddy" } ; public HighlighterTest ( String arg0 ) { } public void testSimpleHighlighter ( ) throws Exception { } public void testGetBestFragmentsSimpleQuery ( ) throws Exception { } public void testGetFuzzyFragments ( ) throws Exception { } public void testGetWildCardFragments ( ) throws Exception { } public void testGetMidWildCardFragments ( ) throws Exception { } public void testGetRangeFragments ( ) throws Exception { } public void testGetBestFragmentsPhrase ( ) throws Exception { } public void testGetBestFragmentsMultiTerm ( ) throws Exception { } public void testGetBestFragmentsWithOr ( ) throws Exception { } public void testGetBestSingleFragment ( ) throws Exception { doSearching ( "Kennedy" ) ; Highlighter highlighter = new Highlighter ( this , new QueryScorer ( query ) ) ; highlighter . setTextFragmenter ( new SimpleFragmenter ( 40 ) ) ; for ( int i = 0 ; i < ( hits . length ( ) ) ; i ++ ) { String text = hits . doc ( i ) . get ( HighlighterTest . FIELD_NAME ) ; TokenStream tokenStream = analyzer . tokenStream ( HighlighterTest . FIELD_NAME , new StringReader ( text ) ) ; String result = highlighter . getBestFragment ( tokenStream , text ) ; System . out . println ( ( "\t" + result ) ) ; } assertTrue ( ( ( "Failed<seq2seq4repair_space>to<seq2seq4repair_space>find<seq2seq4repair_space>correct<seq2seq4repair_space>number<seq2seq4repair_space>of<seq2seq4repair_space>highlights<seq2seq4repair_space>" + ( numHighlights ) ) + "<seq2seq4repair_space>found" ) , ( ( numHighlights ) == 4 ) ) ; numHighlights = 0 ; for ( int i = 0 ; i < ( hits . length ( ) ) ; i ++ ) { String text = hits . doc ( i ) . get ( HighlighterTest . FIELD_NAME ) ; <START_BUG> highlighter . getBestFragment ( analyzer , text ) ; <END_BUG> } assertTrue ( ( ( "Failed<seq2seq4repair_space>to<seq2seq4repair_space>find<seq2seq4repair_space>correct<seq2seq4repair_space>number<seq2seq4repair_space>of<seq2seq4repair_space>highlights<seq2seq4repair_space>" + ( numHighlights ) ) + "<seq2seq4repair_space>found" ) , ( ( numHighlights ) == 4 ) ) ; numHighlights = 0 ; for ( int i = 0 ; i < ( hits . length ( ) ) ; i ++ ) { String text = hits . doc ( i ) . get ( HighlighterTest . FIELD_NAME ) ; highlighter . getBestFragments ( analyzer , text , 10 ) ; } assertTrue ( ( ( "Failed<seq2seq4repair_space>to<seq2seq4repair_space>find<seq2seq4repair_space>correct<seq2seq4repair_space>number<seq2seq4repair_space>of<seq2seq4repair_space>highlights<seq2seq4repair_space>" + ( numHighlights ) ) + "<seq2seq4repair_space>found" ) , ( ( numHighlights ) == 4 ) ) ; } public void testGetBestSingleFragmentWithWeights ( ) throws Exception { } public void testOverlapAnalyzer ( ) throws Exception { } public void testGetSimpleHighlight ( ) throws Exception { } public void testGetTextFragments ( ) throws Exception { } public void testMaxSizeHighlight ( ) throws Exception { } public void testUnRewrittenQuery ( ) throws IOException , ParseException { } public void testNoFragments ( ) throws Exception { } public void testEncoding ( ) throws Exception { } public void testMultiSearcher ( ) throws Exception { } public String highlightTerm ( String originalText , TokenGroup group ) { } public void doSearching ( String queryString ) throws Exception { } void doStandardHighlights ( ) throws Exception { } protected void setUp ( ) throws Exception { } private void addDoc ( IndexWriter writer , String text ) throws IOException { } protected void tearDown ( ) throws Exception { } }

Fix:
highlighter . getBestFragment ( analyzer , HighlighterTest . FIELD_NAME , text ) ;