Buggy code:
class DirectoryReader extends IndexReader implements Cloneable { protected Directory directory ; protected boolean readOnly ; protected CodecProvider codecs ; IndexWriter writer ; private IndexDeletionPolicy deletionPolicy ; private Lock writeLock ; private final SegmentInfos segmentInfos ; private boolean stale ; private final int termInfosIndexDivisor ; private boolean rollbackHasChanges ; private SegmentReader [ ] subReaders ; private ReaderContext topLevelReaderContext ; private int [ ] starts ; private int maxDoc = 0 ; private int numDocs = - 1 ; private boolean hasDeletions = false ; private long maxIndexVersion ; private final boolean applyAllDeletes ; static IndexReader open ( final Directory directory , final IndexDeletionPolicy deletionPolicy , final IndexCommit commit , final boolean readOnly , final int termInfosIndexDivisor , CodecProvider codecs ) throws IOException , CorruptIndexException { } DirectoryReader ( Directory directory , SegmentInfos sis , IndexDeletionPolicy deletionPolicy , boolean readOnly , int termInfosIndexDivisor , CodecProvider codecs ) throws IOException { } DirectoryReader ( IndexWriter writer , SegmentInfos infos , CodecProvider codecs , boolean applyAllDeletes ) throws IOException { } DirectoryReader ( Directory directory , SegmentInfos infos , SegmentReader [ ] oldReaders , int [ ] oldStarts , boolean readOnly , boolean doClone , int termInfosIndexDivisor , CodecProvider codecs , Collection < ReaderFinishedListener > readerFinishedListeners ) throws IOException { } @ Override public String toString ( ) { } private void initialize ( SegmentReader [ ] subReaders ) throws IOException { } @ Override public Bits getLiveDocs ( ) { } @ Override public final synchronized Object clone ( ) { } @ Override public final synchronized IndexReader clone ( boolean openReadOnly ) throws IOException , CorruptIndexException { } @ Override public final IndexReader reopen ( ) throws IOException , CorruptIndexException { } @ Override public final IndexReader reopen ( boolean openReadOnly ) throws IOException , CorruptIndexException { } @ Override public final IndexReader reopen ( final IndexCommit commit ) throws IOException , CorruptIndexException { } private final IndexReader doReopenFromWriter ( boolean openReadOnly , IndexCommit commit ) throws IOException , CorruptIndexException { } private IndexReader doReopen ( final boolean openReadOnly , IndexCommit commit ) throws IOException , CorruptIndexException { } private synchronized IndexReader doReopenNoWriter ( final boolean openReadOnly , IndexCommit commit ) throws IOException , CorruptIndexException { } private synchronized DirectoryReader doReopen ( SegmentInfos infos , boolean doClone , boolean openReadOnly ) throws IOException , CorruptIndexException { } @ Override public long getVersion ( ) { } @ Override public TermFreqVector [ ] getTermFreqVectors ( int n ) throws IOException { } @ Override public TermFreqVector getTermFreqVector ( int n , String field ) throws IOException { } @ Override public void getTermFreqVector ( int docNumber , String field , TermVectorMapper mapper ) throws IOException { } @ Override public void getTermFreqVector ( int docNumber , TermVectorMapper mapper ) throws IOException { } @ Override public boolean isOptimized ( ) { } @ Override public int numDocs ( ) { } @ Override public int maxDoc ( ) { } @ Override public void document ( int docID , StoredFieldVisitor visitor ) throws IOException , CorruptIndexException { } @ Override public boolean hasDeletions ( ) { } @ Override protected void doDelete ( int n ) throws IOException , CorruptIndexException { } @ Override protected void doUndeleteAll ( ) throws IOException , CorruptIndexException { } private int readerIndex ( int n ) { } static final int readerIndex ( int n , int [ ] starts , int numSubReaders ) { } @ Override public boolean hasNorms ( String field ) throws IOException { } @ Override public synchronized byte [ ] norms ( String field ) throws IOException { } @ Override protected void doSetNorm ( int n , String field , byte value ) throws IOException , CorruptIndexException { } @ Override public int docFreq ( Term t ) throws IOException { } @ Override public int docFreq ( String field , BytesRef term ) throws IOException { } @ Override public Fields fields ( ) throws IOException { } @ Override protected void acquireWriteLock ( ) throws IOException , CorruptIndexException , StaleReaderException , LockObtainFailedException { } @ Override protected void doCommit ( Map < String , String > commitUserData ) throws IOException { for ( int i = 0 ; ( ! ( hasChanges ) ) && ( i < ( subReaders . length ) ) ; i ++ ) { hasChanges |= subReaders [ i ] . hasChanges ; } if ( hasChanges ) { segmentInfos . setUserData ( commitUserData ) ; <START_BUG> IndexFileDeleter deleter = new IndexFileDeleter ( directory , ( ( deletionPolicy ) == null ? new KeepOnlyLastCommitDeletionPolicy ( ) : deletionPolicy ) , segmentInfos , null , codecs ) ; <END_BUG> segmentInfos . updateGeneration ( deleter . getLastSegmentInfos ( ) ) ; segmentInfos . changed ( ) ; startCommit ( ) ; final List < SegmentInfo > rollbackSegments = segmentInfos . createBackupSegmentInfos ( false ) ; boolean success = false ; try { for ( int i = 0 ; i < ( subReaders . length ) ; i ++ ) subReaders [ i ] . commit ( ) ; segmentInfos . pruneDeletedSegments ( ) ; directory . sync ( segmentInfos . files ( directory , false ) ) ; segmentInfos . commit ( directory ) ; success = true ; } finally { if ( ! success ) { rollbackCommit ( ) ; deleter . refresh ( ) ; segmentInfos . rollbackSegmentInfos ( rollbackSegments ) ; } } deleter . checkpoint ( segmentInfos , true ) ; deleter . close ( ) ; maxIndexVersion = segmentInfos . getVersion ( ) ; if ( ( writeLock ) != null ) { writeLock . release ( ) ; writeLock = null ; } } hasChanges = false ; } void startCommit ( ) { } void rollbackCommit ( ) { } @ Override public long getUniqueTermCount ( ) throws IOException { } @ Override public Map < String , String > getCommitUserData ( ) { }

Fix:
IndexFileDeleter deleter = new IndexFileDeleter ( directory , ( ( deletionPolicy ) == null ? new KeepOnlyLastCommitDeletionPolicy ( ) : deletionPolicy ) , segmentInfos , null , codecs , null ) ;