Buggy code:
volatile long pendingCommitChangeCount ; private Collection < String > filesToCommit ; final SegmentInfos segmentInfos ; final FieldNumbers globalFieldNumberMap ; private DocumentsWriter docWriter ; final IndexFileDeleter deleter ; private Map < SegmentInfoPerCommit , Boolean > segmentsToMerge = new HashMap < SegmentInfoPerCommit , Boolean > ( ) ; private int mergeMaxNumSegments ; private Lock writeLock ; private volatile boolean closed ; private volatile boolean closing ; private HashSet < SegmentInfoPerCommit > mergingSegments = new HashSet < SegmentInfoPerCommit > ( ) ; private MergePolicy mergePolicy ; private final MergeScheduler mergeScheduler ; private LinkedList < MergePolicy . OneMerge > pendingMerges = new LinkedList < MergePolicy . OneMerge > ( ) ; private Set < MergePolicy . OneMerge > runningMerges = new HashSet < MergePolicy . OneMerge > ( ) ; private List < MergePolicy . OneMerge > mergeExceptions = new ArrayList < MergePolicy . OneMerge > ( ) ; private long mergeGen ; private boolean stopMerges ; final AtomicInteger flushCount = new AtomicInteger ( ) ; final AtomicInteger flushDeletesCount = new AtomicInteger ( ) ; final IndexWriter . ReaderPool readerPool = new IndexWriter . ReaderPool ( ) ; final BufferedDeletesStream bufferedDeletesStream ; private volatile boolean poolReaders ; private final LiveIndexWriterConfig config ; private PayloadProcessorProvider payloadProcessorProvider ; DirectoryReader getReader ( ) throws IOException { } DirectoryReader getReader ( boolean applyAllDeletes ) throws IOException { } class ReaderPool { private final Map < SegmentInfoPerCommit , ReadersAndLiveDocs > readerMap = new HashMap < SegmentInfoPerCommit , ReadersAndLiveDocs > ( ) ; public synchronized boolean infoIsLive ( SegmentInfoPerCommit info ) { } public synchronized void drop ( SegmentInfoPerCommit info ) throws IOException { } public synchronized void release ( ReadersAndLiveDocs rld ) throws IOException { } synchronized void dropAll ( boolean doSave ) throws IOException { } public synchronized void commit ( SegmentInfos infos ) throws IOException { } public synchronized ReadersAndLiveDocs get ( SegmentInfoPerCommit info , boolean create ) { } } public int numDeletedDocs ( SegmentInfoPerCommit info ) { } protected final void ensureOpen ( boolean includePendingClose ) throws AlreadyClosedException { } protected final void ensureOpen ( ) throws AlreadyClosedException { } final Codec codec ; public IndexWriter ( Directory d , IndexWriterConfig conf ) throws IOException { } private FieldInfos getFieldInfos ( SegmentInfo info ) throws IOException { } private FieldNumbers getFieldNumberMap ( ) throws IOException { } public LiveIndexWriterConfig getConfig ( ) { } private void messageState ( ) { } public void close ( ) throws IOException { } public void close ( boolean waitForMerges ) throws IOException { } private synchronized boolean shouldClose ( ) { } private void closeInternal ( boolean waitForMerges , boolean doFlush ) throws IOException { } public Directory getDirectory ( ) { } public Analyzer getAnalyzer ( ) { } public synchronized int maxDoc ( ) { } public synchronized int numDocs ( ) { } public synchronized boolean hasDeletions ( ) { } public void addDocument ( Iterable < ? extends IndexableField > doc ) throws IOException { } public void addDocument ( Iterable < ? extends IndexableField > doc , Analyzer analyzer ) throws IOException { } public void addDocuments ( Iterable < ? extends Iterable < ? extends IndexableField > > docs ) throws IOException { } public void addDocuments ( Iterable < ? extends Iterable < ? extends IndexableField > > docs , Analyzer analyzer ) throws IOException { } public void updateDocuments ( Term delTerm , Iterable < ? extends Iterable < ? extends IndexableField > > docs ) throws IOException { } public void updateDocuments ( Term delTerm , Iterable < ? extends Iterable < ? extends IndexableField > > docs , Analyzer analyzer ) throws IOException { } public void deleteDocuments ( Term term ) throws IOException { } public synchronized boolean tryDeleteDocument ( IndexReader readerIn , int docID ) throws IOException { final AtomicReader reader ; if ( readerIn instanceof AtomicReader ) { reader = ( ( AtomicReader ) ( readerIn ) ) ; } else { <START_BUG> List < AtomicReaderContext > leaves = readerIn . getTopReaderContext ( ) . leaves ( ) ; <END_BUG> int subIndex = ReaderUtil . subIndex ( docID , leaves ) ; reader = leaves . get ( subIndex ) . reader ( ) ; docID -= leaves . get ( subIndex ) . docBase ; assert docID >= 0 ; assert docID < ( reader . maxDoc ( ) ) ; } if ( ! ( reader instanceof SegmentReader ) ) { throw new IllegalArgumentException ( "the<seq2seq4repair_space>reader<seq2seq4repair_space>must<seq2seq4repair_space>be<seq2seq4repair_space>a<seq2seq4repair_space>SegmentReader<seq2seq4repair_space>or<seq2seq4repair_space>composite<seq2seq4repair_space>reader<seq2seq4repair_space>containing<seq2seq4repair_space>only<seq2seq4repair_space>SegmentReaders" ) ; } final SegmentInfoPerCommit info = ( ( SegmentReader ) ( reader ) ) . getSegmentInfo ( ) ; if ( ( segmentInfos . indexOf ( info ) ) != ( - 1 ) ) { ReadersAndLiveDocs rld = readerPool . get ( info , false ) ; if ( rld != null ) { synchronized ( bufferedDeletesStream ) { rld . initWritableLiveDocs ( ) ; if ( rld . delete ( docID ) ) { final int fullDelCount = ( rld . info . getDelCount ( ) ) + ( rld . getPendingDeleteCount ( ) ) ; if ( fullDelCount == ( rld . info . info . getDocCount ( ) ) ) { if ( ! ( mergingSegments . contains ( rld . info ) ) ) { segmentInfos . remove ( rld . info ) ; readerPool . drop ( rld . info ) ; checkpoint ( ) ; } } } return true ; } } else { } } else { } return false ; } public void deleteDocuments ( Term ... terms ) throws IOException { } public void deleteDocuments ( Query query ) throws IOException { } public void deleteDocuments ( Query ... queries ) throws IOException { } public void updateDocument ( Term term , Iterable < ? extends IndexableField > doc ) throws IOException { } public void updateDocument ( Term term , Iterable < ? extends IndexableField > doc , Analyzer analyzer ) throws IOException { } final synchronized int getSegmentCount ( ) { }

Fix:
List < AtomicReaderContext > leaves = readerIn . leaves ( ) ;