Buggy code:
public class TestIndexWriterReader extends LuceneTestCase { static PrintStream infoStream ; public static class HeavyAtomicInt { private int value ; public HeavyAtomicInt ( int start ) { } public synchronized int addAndGet ( int inc ) { } public synchronized int incrementAndGet ( ) { } public synchronized int intValue ( ) { } } public static int count ( Term t , IndexReader r ) throws IOException { } public void testUpdateDocument ( ) throws Exception { } public void testAddIndexes ( ) throws Exception { } public void testAddIndexes2 ( ) throws Exception { } public void testDeleteFromIndexWriter ( ) throws Exception { boolean optimize = true ; Directory dir1 = new MockRAMDirectory ( ) ; <START_BUG> IndexWriter writer = new IndexWriter ( dir1 , new IndexWriterConfig ( TEST_VERSION_CURRENT , new MockAnalyzer ( ) ) ) ; <END_BUG> writer . setInfoStream ( TestIndexWriterReader . infoStream ) ; TestIndexWriterReader . createIndexNoClose ( ( ! optimize ) , "index1" , writer ) ; writer . flush ( false , true , true ) ; IndexReader r1 = writer . getReader ( ) ; String id10 = r1 . document ( 10 ) . getField ( "id" ) . stringValue ( ) ; writer . deleteDocuments ( new Term ( "id" , id10 ) ) ; IndexReader r2 = writer . getReader ( ) ; assertEquals ( 1 , TestIndexWriterReader . count ( new Term ( "id" , id10 ) , r1 ) ) ; assertEquals ( 0 , TestIndexWriterReader . count ( new Term ( "id" , id10 ) , r2 ) ) ; String id50 = r1 . document ( 50 ) . getField ( "id" ) . stringValue ( ) ; assertEquals ( 1 , TestIndexWriterReader . count ( new Term ( "id" , id50 ) , r1 ) ) ; writer . deleteDocuments ( new Term ( "id" , id50 ) ) ; IndexReader r3 = writer . getReader ( ) ; assertEquals ( 0 , TestIndexWriterReader . count ( new Term ( "id" , id10 ) , r3 ) ) ; assertEquals ( 0 , TestIndexWriterReader . count ( new Term ( "id" , id50 ) , r3 ) ) ; String id75 = r1 . document ( 75 ) . getField ( "id" ) . stringValue ( ) ; writer . deleteDocuments ( new org . apache . lucene . search . TermQuery ( new Term ( "id" , id75 ) ) ) ; IndexReader r4 = writer . getReader ( ) ; assertEquals ( 1 , TestIndexWriterReader . count ( new Term ( "id" , id75 ) , r3 ) ) ; assertEquals ( 0 , TestIndexWriterReader . count ( new Term ( "id" , id75 ) , r4 ) ) ; r1 . close ( ) ; r2 . close ( ) ; r3 . close ( ) ; r4 . close ( ) ; writer . close ( ) ; writer = new IndexWriter ( dir1 , new IndexWriterConfig ( TEST_VERSION_CURRENT , new MockAnalyzer ( ) ) ) ; writer . setInfoStream ( TestIndexWriterReader . infoStream ) ; IndexReader w2r1 = writer . getReader ( ) ; assertEquals ( 0 , TestIndexWriterReader . count ( new Term ( "id" , id10 ) , w2r1 ) ) ; w2r1 . close ( ) ; writer . close ( ) ; dir1 . close ( ) ; } public void testAddIndexesAndDoDeletesThreads ( ) throws Throwable { } private class AddDirectoriesThreads { Directory addDir ; static final int NUM_THREADS = 5 ; static final int NUM_INIT_DOCS = 100 ; int numDirs ; final Thread [ ] threads = new Thread [ TestIndexWriterReader . AddDirectoriesThreads . NUM_THREADS ] ; IndexWriter mainWriter ; final List < Throwable > failures = new ArrayList < Throwable > ( ) ; IndexReader [ ] readers ; boolean didClose = false ; TestIndexWriterReader . HeavyAtomicInt count = new TestIndexWriterReader . HeavyAtomicInt ( 0 ) ; TestIndexWriterReader . HeavyAtomicInt numaddIndexes = new TestIndexWriterReader . HeavyAtomicInt ( 0 ) ; public AddDirectoriesThreads ( int numDirs , IndexWriter mainWriter ) throws Throwable { } void joinThreads ( ) { } void close ( boolean doWait ) throws Throwable { } void closeDir ( ) throws Throwable { } void handle ( Throwable t ) { } void launchThreads ( final int numIter ) { } void doBody ( int j , Directory [ ] dirs ) throws Throwable { } } public void testIndexWriterReopenSegmentOptimize ( ) throws Exception { } public void testIndexWriterReopenSegment ( ) throws Exception { } public void doTestIndexWriterReopenSegment ( boolean optimize ) throws Exception { } public static Document createDocument ( int n , String indexName , int numFields ) { } public static void createIndex ( Directory dir1 , String indexName , boolean multiSegment ) throws IOException { } public static void createIndexNoClose ( boolean multiSegment , String indexName , IndexWriter w ) throws IOException { } private static class MyWarmer extends IndexWriter . IndexReaderWarmer { int warmCount ; @ Override public void warm ( IndexReader reader ) throws IOException { } } public void testMergeWarmer ( ) throws Exception { } public void testAfterCommit ( ) throws Exception { } public void testAfterClose ( ) throws Exception { } public void testDuringAddIndexes ( ) throws Exception { } public void testDuringAddDelete ( ) throws Exception { } public void testExpungeDeletes ( ) throws Throwable { } public void testDeletesNumDocs ( ) throws Throwable { } public void testEmptyIndex ( ) throws Exception { } }

Fix:
IndexWriter writer = new IndexWriter ( dir1 , new IndexWriterConfig ( TEST_VERSION_CURRENT , new MockAnalyzer ( ) ) . setReaderTermsIndexDivisor ( 2 ) ) ;