Buggy code:
public final void prepareCommit ( ) throws IOException , CorruptIndexException { } public final void prepareCommit ( Map < String , String > commitUserData ) throws IOException , CorruptIndexException { } private final Object commitLock = new Object ( ) ; public final void commit ( ) throws IOException , CorruptIndexException { } public final void commit ( Map < String , String > commitUserData ) throws IOException , CorruptIndexException { } private final void commitInternal ( Map < String , String > commitUserData ) throws IOException , CorruptIndexException { } private final synchronized void finishCommit ( ) throws IOException , CorruptIndexException { } protected final void flush ( boolean triggerMerge , boolean applyAllDeletes ) throws IOException , CorruptIndexException { } private synchronized boolean doFlush ( boolean applyAllDeletes ) throws IOException , CorruptIndexException { } public final long ramSizeInBytes ( ) { } public final synchronized int numRamDocs ( ) { } private void ensureValidMerge ( MergePolicy . OneMerge merge ) { } private synchronized void commitMergedDeletes ( MergePolicy . OneMerge merge , SegmentReader mergedReader ) throws IOException { } private synchronized boolean commitMerge ( MergePolicy . OneMerge merge , SegmentReader mergedReader ) throws IOException { } private final void handleMergeException ( Throwable t , MergePolicy . OneMerge merge ) throws IOException { } final void merge ( MergePolicy . OneMerge merge ) throws IOException , CorruptIndexException { } void mergeSuccess ( MergePolicy . OneMerge merge ) { } final synchronized boolean registerMerge ( MergePolicy . OneMerge merge ) throws MergeAbortedException { } final synchronized void mergeInit ( MergePolicy . OneMerge merge ) throws IOException { } private synchronized void _mergeInit ( MergePolicy . OneMerge merge ) throws IOException { } private void setDiagnostics ( SegmentInfo info , String source ) { } private void setDiagnostics ( SegmentInfo info , String source , Map < String , String > details ) { } final synchronized void mergeFinish ( MergePolicy . OneMerge merge ) throws IOException { } private synchronized void closeMergeReaders ( MergePolicy . OneMerge merge , boolean suppressExceptions ) throws IOException { } private int mergeMiddle ( MergePolicy . OneMerge merge ) throws IOException , CorruptIndexException { merge . checkAborted ( directory ) ; final String mergedName = merge . info . name ; int mergedDocCount = 0 ; SegmentInfos sourceSegments = merge . segments ; SegmentMerger merger = new SegmentMerger ( directory , termIndexInterval , mergedName , merge , codecs , payloadProcessorProvider , ( ( FieldInfos ) ( docWriter . getFieldInfos ( ) . clone ( ) ) ) ) ; if ( ( infoStream ) != null ) { message ( ( ( ( "merging<seq2seq4repair_space>" + ( merge . segString ( directory ) ) ) + "<seq2seq4repair_space>mergeVectors=" ) + ( merger . fieldInfos ( ) . hasVectors ( ) ) ) ) ; } merge . readers = new ArrayList < SegmentReader > ( ) ; merge . readerClones = new ArrayList < SegmentReader > ( ) ; merge . info . setHasVectors ( merger . fieldInfos ( ) . hasVectors ( ) ) ; boolean success = false ; try { int totDocCount = 0 ; int segUpto = 0 ; while ( segUpto < ( sourceSegments . size ( ) ) ) { final SegmentInfo info = sourceSegments . info ( segUpto ) ; final SegmentReader reader = readerPool . get ( info , true , IndexWriter . MERGE_READ_BUFFER_SIZE , ( - ( config . getReaderTermsIndexDivisor ( ) ) ) ) ; merge . readers . add ( reader ) ; final SegmentReader clone = ( ( SegmentReader ) ( reader . clone ( true ) ) ) ; merge . readerClones . add ( clone ) ; if ( ( clone . numDocs ( ) ) > 0 ) { merger . add ( clone ) ; totDocCount += clone . numDocs ( ) ; } segUpto ++ ; } if ( ( infoStream ) != null ) { message ( ( ( "merge:<seq2seq4repair_space>total<seq2seq4repair_space>" + totDocCount ) + "<seq2seq4repair_space>docs" ) ) ; } merge . checkAborted ( directory ) ; mergedDocCount = merge . info . docCount = merger . merge ( ) ; merge . info . setSegmentCodecs ( merger . getSegmentCodecs ( ) ) ; if ( ( infoStream ) != null ) { message ( ( "merge<seq2seq4repair_space>segmentCodecs=" + ( merger . getSegmentCodecs ( ) ) ) ) ; message ( ( ( ( "merge<seq2seq4repair_space>store<seq2seq4repair_space>matchedCount=" + ( merger . getMatchedSubReaderCount ( ) ) ) + "<seq2seq4repair_space>vs<seq2seq4repair_space>" ) + ( merge . readers . size ( ) ) ) ) ; } <START_BUG> anyNonBulkMerges |= ( merger . getMatchedSubReaderCount ( ) ) != ( merge . readers . size ( ) ) ; <END_BUG> assert mergedDocCount == totDocCount : ( ( "mergedDocCount=" + mergedDocCount ) + "<seq2seq4repair_space>vs<seq2seq4repair_space>" ) + totDocCount ; merge . info . setHasProx ( merger . fieldInfos ( ) . hasProx ( ) ) ; boolean useCompoundFile ; synchronized ( this ) { useCompoundFile = mergePolicy . useCompoundFile ( segmentInfos , merge . info ) ; } if ( useCompoundFile ) { success = false ; final String compoundFileName = IndexFileNames . segmentFileName ( mergedName , "" , COMPOUND_FILE_EXTENSION ) ; try { if ( ( infoStream ) != null ) { message ( ( "create<seq2seq4repair_space>compound<seq2seq4repair_space>file<seq2seq4repair_space>" + compoundFileName ) ) ; } merger . createCompoundFile ( compoundFileName , merge . info ) ; success = true ; } catch ( IOException ioe ) { synchronized ( this ) { if ( merge . isAborted ( ) ) { } else { handleMergeException ( ioe , merge ) ; } } } catch ( Throwable t ) { handleMergeException ( t , merge ) ; } finally { if ( ! success ) { if ( ( infoStream ) != null ) { message ( "hit<seq2seq4repair_space>exception<seq2seq4repair_space>creating<seq2seq4repair_space>compound<seq2seq4repair_space>file<seq2seq4repair_space>during<seq2seq4repair_space>merge" ) ; } synchronized ( this ) { deleter . deleteFile ( compoundFileName ) ; deleter . deleteNewFiles ( merge . info . files ( ) ) ; } } } success = false ;

Fix:
anyNonBulkMerges |= merger . getAnyNonBulkMerges ( ) ;