Buggy code:
public class TestIndexWriterDelete extends LuceneTestCase { public void testSimpleCase ( ) throws IOException { } public void testNonRAMDelete ( ) throws IOException { } public void testMaxBufferedDeletes ( ) throws IOException { } public void testRAMDeletes ( ) throws IOException { } public void testBothDeletes ( ) throws IOException { } public void testBatchDeletes ( ) throws IOException { } public void testDeleteAll ( ) throws IOException { } public void testDeleteAllRollback ( ) throws IOException { } public void testDeleteAllNRT ( ) throws IOException { } private void updateDoc ( IndexWriter modifier , int id , int value ) throws IOException { } private void addDoc ( IndexWriter modifier , int id , int value ) throws IOException { } private int getHitCount ( Directory dir , Term term ) throws IOException { } public void testDeletesOnDiskFull ( ) throws IOException { } public void testUpdatesOnDiskFull ( ) throws IOException { } private void doTestOperationsOnDiskFull ( boolean updates ) throws IOException { } public void testErrorAfterApplyDeletes ( ) throws IOException { } public void testErrorInDocsWriterAdd ( ) throws IOException { } public void testDeleteNullQuery ( ) throws IOException { } public void testDeleteAllSlowly ( ) throws Exception { } public void testIndexingThenDeleting ( ) throws Exception { } public void testFlushPushedDeletesByRAM ( ) throws Exception { } public void testFlushPushedDeletesByCount ( ) throws Exception { } public void testApplyDeletesOnFlush ( ) throws Exception { Directory dir = newDirectory ( ) ; final AtomicInteger docsInSegment = new AtomicInteger ( ) ; final AtomicBoolean closing = new AtomicBoolean ( ) ; final AtomicBoolean sawAfterFlush = new AtomicBoolean ( ) ; IndexWriter w = new IndexWriter ( dir , newIndexWriterConfig ( TEST_VERSION_CURRENT , new org . apache . lucene . analysis . MockAnalyzer ( random ) ) . setRAMBufferSizeMB ( 0.5 ) . setMaxBufferedDocs ( ( - 1 ) ) . setMergePolicy ( NO_COMPOUND_FILES ) . setReaderPooling ( false ) ) { @ Override public void doAfterFlush ( ) { <START_BUG> assertTrue ( ( ( "only<seq2seq4repair_space>" + ( docsInSegment . get ( ) ) ) + "<seq2seq4repair_space>in<seq2seq4repair_space>segment" ) , ( ( closing . get ( ) ) || ( ( docsInSegment . get ( ) ) >= 10 ) ) ) ; <END_BUG> docsInSegment . set ( 0 ) ; sawAfterFlush . set ( true ) ; } } ; w . setInfoStream ( ( VERBOSE ? System . out : null ) ) ; int id = 0 ; while ( true ) { StringBuilder sb = new StringBuilder ( ) ; for ( int termIDX = 0 ; termIDX < 100 ; termIDX ++ ) { sb . append ( '<seq2seq4repair_space>' ) . append ( _TestUtil . randomRealisticUnicodeString ( random ) ) ; } if ( id == 500 ) { w . deleteDocuments ( new Term ( "id" , "0" ) ) ; } Document doc = new Document ( ) ; doc . add ( newField ( "id" , ( "" + id ) , NOT_ANALYZED ) ) ; doc . add ( newField ( "body" , sb . toString ( ) , ANALYZED ) ) ; w . updateDocument ( new Term ( "id" , ( "" + id ) ) , doc ) ; docsInSegment . incrementAndGet ( ) ; if ( dir . fileExists ( "_0_1.del" ) ) { if ( VERBOSE ) { System . out . println ( ( "TEST:<seq2seq4repair_space>deletes<seq2seq4repair_space>created<seq2seq4repair_space>@<seq2seq4repair_space>id=" + id ) ) ; } break ; } id ++ ; } closing . set ( true ) ; assertTrue ( sawAfterFlush . get ( ) ) ; w . close ( ) ; dir . close ( ) ; } }

Fix:
assertTrue ( ( ( "only<seq2seq4repair_space>" + ( docsInSegment . get ( ) ) ) + "<seq2seq4repair_space>in<seq2seq4repair_space>segment" ) , ( ( closing . get ( ) ) || ( ( docsInSegment . get ( ) ) >= 7 ) ) ) ;