Buggy code:
public class TestTimeLimitingCollector extends LuceneTestCase { private static final int SLOW_DOWN = 47 ; private static final long TIME_ALLOWED = 17 * ( TestTimeLimitingCollector . SLOW_DOWN ) ; private static final double MULTI_THREAD_SLACK = 7 ; private static final int N_DOCS = 3000 ; private static final int N_THREADS = 50 ; private Searcher searcher ; private final String FIELD_NAME = "body" ; private Query query ; public TestTimeLimitingCollector ( String name ) { } protected void setUp ( ) throws Exception { super . setUp ( ) ; final String [ ] docText = new String [ ] { "docThatNeverMatchesSoWeCanRequireLastDocCollectedToBeGreaterThanZero" , "one<seq2seq4repair_space>blah<seq2seq4repair_space>three" , "one<seq2seq4repair_space>foo<seq2seq4repair_space>three<seq2seq4repair_space>multiOne" , "one<seq2seq4repair_space>foobar<seq2seq4repair_space>three<seq2seq4repair_space>multiThree" , "blueberry<seq2seq4repair_space>pancakes" , "blueberry<seq2seq4repair_space>pie" , "blueberry<seq2seq4repair_space>strudel" , "blueberry<seq2seq4repair_space>pizza" } ; Directory directory = new RAMDirectory ( ) ; IndexWriter iw = new IndexWriter ( directory , new WhitespaceAnalyzer ( ) , true , MaxFieldLength . UNLIMITED ) ; for ( int i = 0 ; i < ( TestTimeLimitingCollector . N_DOCS ) ; i ++ ) { add ( docText [ ( i % ( docText . length ) ) ] , iw ) ; } iw . close ( ) ; <START_BUG> searcher = new IndexSearcher ( directory ) ; <END_BUG> String qtxt = "one" ; for ( int i = 0 ; i < ( docText . length ) ; i ++ ) { qtxt += '<seq2seq4repair_space>' + ( docText [ i ] ) ; } QueryParser queryParser = new QueryParser ( FIELD_NAME , new WhitespaceAnalyzer ( ) ) ; query = queryParser . parse ( qtxt ) ; searcher . search ( query , null , 1000 ) ; } public void tearDown ( ) throws Exception { } private void add ( String value , IndexWriter iw ) throws IOException { } private void search ( Collector collector ) throws Exception { } public void testSearch ( ) { } private void doTestSearch ( ) { } private Collector createTimedCollector ( TestTimeLimitingCollector . MyHitCollector hc , long timeAllowed , boolean greedy ) { } public void testTimeoutGreedy ( ) { } public void testTimeoutNotGreedy ( ) { } private void doTestTimeout ( boolean multiThreaded , boolean greedy ) { } private long maxTime ( boolean multiThreaded ) { } private String maxTimeStr ( boolean multiThreaded ) { } public void testModifyResolution ( ) { } public void testSearchMultiThreaded ( ) throws Exception { } public void testTimeoutMultiThreaded ( ) throws Exception { } private void doTestMultiThreads ( final boolean withTimeout ) throws Exception { } private class MyHitCollector extends Collector { private final BitSet bits = new BitSet ( ) ; private int slowdown = 0 ; private int lastDocCollected = - 1 ; private int docBase = 0 ; public void setSlowDown ( int milliseconds ) { } public int hitCount ( ) { } public int getLastDocCollected ( ) { } public void setScorer ( Scorer scorer ) throws IOException { } public void collect ( final int doc ) throws IOException { } public void setNextReader ( IndexReader reader , int base ) { } public boolean acceptsDocsOutOfOrder ( ) { } } }

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