Buggy code:
public void forceMergeDeletes ( boolean doWait ) throws IOException , CorruptIndexException { } public void forceMergeDeletes ( ) throws IOException , CorruptIndexException { } public final void maybeMerge ( ) throws IOException , CorruptIndexException { } private final void maybeMerge ( int maxNumSegments ) throws IOException , CorruptIndexException { } private synchronized void updatePendingMerges ( int maxNumSegments ) throws IOException , CorruptIndexException { } public synchronized Collection < SegmentInfo > getMergingSegments ( ) { } public synchronized OneMerge getNextMerge ( ) { } public void rollback ( ) throws IOException { } private void rollbackInternal ( ) throws IOException { } public synchronized void deleteAll ( ) throws IOException { } private synchronized void finishMerges ( boolean waitForMerges ) throws IOException { } public synchronized void waitForMerges ( ) { } synchronized void checkpoint ( ) throws IOException { } SegmentInfo prepareFlushedSegment ( FlushedSegment flushedSegment ) throws IOException { } synchronized void publishFrozenDeletes ( FrozenBufferedDeletes packet ) throws IOException { } synchronized void publishFlushedSegment ( SegmentInfo newSegment , FrozenBufferedDeletes packet , FrozenBufferedDeletes globalPacket ) throws IOException { } synchronized boolean useCompoundFile ( SegmentInfo segmentInfo ) throws IOException { } private synchronized void resetMergeExceptions ( ) { } private void noDupDirs ( Directory ... dirs ) { } public void addIndexes ( Directory ... dirs ) throws IOException , CorruptIndexException { } public void addIndexes ( IndexReader ... readers ) throws IOException , CorruptIndexException { } private void copySegmentAsIs ( SegmentInfo info , String segName , Map < String , String > dsNames , Set < String > dsFilesCopied , IOContext context ) throws IOException { } protected void doAfterFlush ( ) throws IOException { } protected void doBeforeFlush ( ) throws IOException { } 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 { } private final Object fullFlushLock = new Object ( ) ; protected final void flush ( boolean triggerMerge , boolean applyAllDeletes ) throws IOException , CorruptIndexException { } private boolean doFlush ( boolean applyAllDeletes ) throws IOException , CorruptIndexException { } final synchronized void maybeApplyDeletes ( boolean applyAllDeletes ) throws IOException { } final synchronized void applyAllDeletes ( ) throws IOException { } public final long ramSizeInBytes ( ) { } DocumentsWriter getDocsWriter ( ) { } public final synchronized int numRamDocs ( ) { } private synchronized void ensureValidMerge ( MergePolicy . OneMerge merge ) throws IOException { } private synchronized IndexWriter . ReadersAndLiveDocs commitMergedDeletes ( MergePolicy . OneMerge merge ) throws IOException { } private synchronized boolean commitMerge ( MergePolicy . OneMerge merge ) throws IOException { assert testPoint ( "startCommitMerge" ) ; if ( hitOOM ) { throw new IllegalStateException ( "this<seq2seq4repair_space>writer<seq2seq4repair_space>hit<seq2seq4repair_space>an<seq2seq4repair_space>OutOfMemoryError;<seq2seq4repair_space>cannot<seq2seq4repair_space>complete<seq2seq4repair_space>merge" ) ; } if ( infoStream . isEnabled ( "IW" ) ) { infoStream . message ( "IW" , ( ( ( "commitMerge:<seq2seq4repair_space>" + ( segString ( merge . segments ) ) ) + "<seq2seq4repair_space>index=" ) + ( segString ( ) ) ) ) ; } assert merge . registerDone ; if ( merge . isAborted ( ) ) { if ( infoStream . isEnabled ( "IW" ) ) { infoStream . message ( "IW" , "commitMerge:<seq2seq4repair_space>skip:<seq2seq4repair_space>it<seq2seq4repair_space>was<seq2seq4repair_space>aborted" ) ; } return false ; } <START_BUG> final IndexWriter . ReadersAndLiveDocs mergedDeletes = commitMergedDeletes ( merge ) ; <END_BUG> assert ( mergedDeletes == null ) || ( ( mergedDeletes . pendingDeleteCount ) != 0 ) ; assert ! ( segmentInfos . contains ( merge . info ) ) ; final boolean allDeleted = ( ( ( merge . segments . size ( ) ) == 0 ) || ( ( merge . info . docCount ) == 0 ) ) || ( ( mergedDeletes != null ) && ( ( mergedDeletes . pendingDeleteCount ) == ( merge . info . docCount ) ) ) ; if ( infoStream . isEnabled ( "IW" ) ) { if ( allDeleted ) { infoStream . message ( "IW" , ( ( ( "merged<seq2seq4repair_space>segment<seq2seq4repair_space>" + ( merge . info ) ) + "<seq2seq4repair_space>is<seq2seq4repair_space>100%<seq2seq4repair_space>deleted" ) + ( keepFullyDeletedSegments ? "" : ";<seq2seq4repair_space>skipping<seq2seq4repair_space>insert" ) ) ) ; } } final boolean dropSegment = allDeleted && ( ! ( keepFullyDeletedSegments ) ) ; assert ( ( merge . segments . size ( ) ) > 0 ) || dropSegment ; assert ( ( ( merge . info . docCount ) != 0 ) || ( keepFullyDeletedSegments ) ) || dropSegment ; segmentInfos . applyMergeChanges ( merge , dropSegment ) ; if ( dropSegment ) { readerPool . drop ( merge . info ) ; deleter . deleteNewFiles ( merge . info . files ( ) ) ; assert ! ( segmentInfos . contains ( merge . info ) ) ; } else { if ( ( mergedDeletes != null ) && ( ! ( poolReaders ) ) ) { mergedDeletes . writeLiveDocs ( directory ) ; readerPool . drop ( merge . info ) ; } } closeMergeReaders ( merge , false ) ; checkpoint ( ) ; if ( infoStream . isEnabled ( "IW" ) ) { infoStream . message ( "IW" , ( "after<seq2seq4repair_space>commit:<seq2seq4repair_space>" + ( segString ( ) ) ) ) ; } if ( ( ( merge . maxNumSegments ) != ( - 1 ) ) && ( ! dropSegment ) ) { if ( ! ( segmentsToMerge . containsKey ( merge . info ) ) ) { segmentsToMerge . put ( merge . info , Boolean . FALSE ) ; } } return true ;

Fix:
final IndexWriter . ReadersAndLiveDocs mergedDeletes = ( ( merge . info . docCount ) == 0 ) ? null : commitMergedDeletes ( merge ) ;