Buggy code:
protected boolean readOnly ; 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 int [ ] starts ; private Map < String , byte [ ] > normsCache = new HashMap < String , byte [ ] > ( ) ; 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 ) throws IOException , CorruptIndexException { } DirectoryReader ( Directory directory , SegmentInfos sis , IndexDeletionPolicy deletionPolicy , boolean readOnly , int termInfosIndexDivisor , Collection < ReaderFinishedListener > readerFinishedListeners ) throws IOException { } DirectoryReader ( IndexWriter writer , SegmentInfos infos , int termInfosIndexDivisor , boolean applyAllDeletes ) throws IOException { } DirectoryReader ( Directory directory , SegmentInfos infos , SegmentReader [ ] oldReaders , int [ ] oldStarts , Map < String , byte [ ] > oldNormsCache , boolean readOnly , boolean doClone , int termInfosIndexDivisor , Collection < ReaderFinishedListener > readerFinishedListeners ) throws IOException { } @ Override public String toString ( ) { } private void initialize ( SegmentReader [ ] subReaders ) throws IOException { } @ 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 Document document ( int n , FieldSelector fieldSelector ) throws IOException , CorruptIndexException { } @ Override public boolean isDeleted ( int n ) { } @ 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 public synchronized void norms ( String field , byte [ ] result , int offset ) throws IOException { } @ Override protected void doSetNorm ( int n , String field , byte value ) throws IOException , CorruptIndexException { } @ Override public TermEnum terms ( ) throws IOException { } @ Override public TermEnum terms ( Term term ) throws IOException { } @ Override public int docFreq ( Term t ) throws IOException { } @ Override public TermDocs termDocs ( ) throws IOException { } @ Override public TermDocs termDocs ( Term term ) throws IOException { } @ Override public TermPositions termPositions ( ) throws IOException { } @ Override protected void acquireWriteLock ( ) throws IOException , CorruptIndexException , StaleReaderException , LockObtainFailedException { } @ Override protected void doCommit ( Map < String , String > commitUserData ) throws IOException { if ( hasChanges ) { segmentInfos . setUserData ( commitUserData ) ; <START_BUG> IndexFileDeleter deleter = new IndexFileDeleter ( directory , ( ( deletionPolicy ) == null ? new KeepOnlyLastCommitDeletionPolicy ( ) : deletionPolicy ) , segmentInfos , null ) ; <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 ( ) { }

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