Buggy code:
public abstract class ThreadedIndexingAndSearchingTestCase extends LuceneTestCase { protected final AtomicBoolean failed = new AtomicBoolean ( ) ; protected final AtomicInteger addCount = new AtomicInteger ( ) ; protected final AtomicInteger delCount = new AtomicInteger ( ) ; protected final AtomicInteger packCount = new AtomicInteger ( ) ; protected Directory dir ; protected IndexWriter writer ; private static class SubDocs { public final String packID ; public final List < String > subIDs ; public boolean deleted ; public SubDocs ( String packID , List < String > subIDs ) { } } protected abstract IndexSearcher getCurrentSearcher ( ) throws Exception { } protected abstract IndexSearcher getFinalSearcher ( ) throws Exception { } protected void releaseSearcher ( IndexSearcher s ) throws Exception { } protected abstract void doSearching ( ExecutorService es , long stopTime ) throws Exception { } protected Directory getDirectory ( Directory in ) { } protected void updateDocuments ( Term id , List < ? extends Iterable < ? extends IndexableField > > docs ) throws Exception { } protected void addDocuments ( Term id , List < ? extends Iterable < ? extends IndexableField > > docs ) throws Exception { } protected void addDocument ( Term id , Iterable < ? extends IndexableField > doc ) throws Exception { } protected void updateDocument ( Term term , Iterable < ? extends IndexableField > doc ) throws Exception { } protected void deleteDocuments ( Term term ) throws Exception { } protected void doAfterIndexingThreadDone ( ) { } private Thread [ ] launchIndexingThreads ( final LineFileDocs docs , int numThreads , final long stopTime , final Set < String > delIDs , final Set < String > delPackIDs , final List < ThreadedIndexingAndSearchingTestCase . SubDocs > allSubDocs ) throws Exception { } protected void runSearchThreads ( final long stopTimeMS ) throws Exception { final int numThreads = _TestUtil . nextInt ( random , 1 , 5 ) ; final Thread [ ] searchThreads = new Thread [ numThreads ] ; final AtomicInteger totHits = new AtomicInteger ( ) ; final AtomicInteger totTermCount = new AtomicInteger ( 100 ) ; for ( int thread = 0 ; thread < ( searchThreads . length ) ; thread ++ ) { searchThreads [ thread ] = new Thread ( ) { @ Override public void run ( ) { while ( ( System . currentTimeMillis ( ) ) < stopTimeMS ) { try { final IndexSearcher s = getCurrentSearcher ( ) ; try { if ( ( s . getIndexReader ( ) . numDocs ( ) ) > 0 ) { smokeTestSearcher ( s ) ; Fields fields = MultiFields . getFields ( s . getIndexReader ( ) ) ; if ( fields == null ) { continue ; } Terms terms = fields . terms ( "body" ) ; if ( terms == null ) { continue ; } TermsEnum termsEnum = terms . iterator ( null ) ; int seenTermCount = 0 ; int shift ; int trigger ; <START_BUG> if ( ( totTermCount . get ( ) ) < 10 ) { <END_BUG> shift = 0 ; trigger = 1 ; } else { trigger = ( totTermCount . get ( ) ) // 30 ; shift = random . nextInt ( trigger ) ; } while ( true ) { BytesRef term = termsEnum . next ( ) ; if ( term == null ) { if ( seenTermCount == 0 ) { break ; } totTermCount . set ( seenTermCount ) ; break ; } seenTermCount ++ ; if ( trigger == 0 ) { trigger = 1 ; } if ( ( ( seenTermCount + shift ) % trigger ) == 0 ) { totHits . addAndGet ( runQuery ( s , new TermQuery ( new Term ( "body" , term ) ) ) ) ; } } } } finally { releaseSearcher ( s ) ; } } catch ( Throwable t ) { System . out . println ( ( ( Thread . currentThread ( ) . getName ( ) ) + ":<seq2seq4repair_space>hit<seq2seq4repair_space>exc" ) ) ; failed . set ( true ) ; t . printStackTrace ( System . out ) ; throw new RuntimeException ( t ) ; } } } } ; searchThreads [ thread ] . setDaemon ( true ) ; searchThreads [ thread ] . start ( ) ; } for ( int thread = 0 ; thread < ( searchThreads . length ) ; thread ++ ) { searchThreads [ thread ] . join ( ) ; } if ( VERBOSE ) { System . out . println ( ( "TEST:<seq2seq4repair_space>DONE<seq2seq4repair_space>search:<seq2seq4repair_space>totHits=" + totHits ) ) ; } } protected void doAfterWriter ( ExecutorService es ) throws Exception { } protected void doClose ( ) throws Exception { } public void runTest ( String testName ) throws Exception { } private int runQuery ( IndexSearcher s , Query q ) throws Exception { } protected void smokeTestSearcher ( IndexSearcher s ) throws Exception { } }

Fix:
if ( ( totTermCount . get ( ) ) < 30 ) {