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 , 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 protected final IndexReader doOpenIfChanged ( ) throws IOException , CorruptIndexException { } @ Override protected final IndexReader doOpenIfChanged ( boolean openReadOnly ) throws IOException , CorruptIndexException { } @ Override protected final IndexReader doOpenIfChanged ( final IndexCommit commit ) throws IOException , CorruptIndexException { } @ Override protected final IndexReader doOpenIfChanged ( IndexWriter writer , boolean applyAllDeletes ) throws IOException , CorruptIndexException { } private final IndexReader doOpenFromWriter ( boolean openReadOnly , IndexCommit commit ) throws IOException , CorruptIndexException { assert readOnly ; if ( ! openReadOnly ) { throw new IllegalArgumentException ( "a<seq2seq4repair_space>reader<seq2seq4repair_space>obtained<seq2seq4repair_space>from<seq2seq4repair_space>IndexWriter.getReader()<seq2seq4repair_space>can<seq2seq4repair_space>only<seq2seq4repair_space>be<seq2seq4repair_space>reopened<seq2seq4repair_space>with<seq2seq4repair_space>openReadOnly=true<seq2seq4repair_space>(got<seq2seq4repair_space>false)" ) ; } if ( commit != null ) { throw new IllegalArgumentException ( "a<seq2seq4repair_space>reader<seq2seq4repair_space>obtained<seq2seq4repair_space>from<seq2seq4repair_space>IndexWriter.getReader()<seq2seq4repair_space>cannot<seq2seq4repair_space>currently<seq2seq4repair_space>accept<seq2seq4repair_space>a<seq2seq4repair_space>commit" ) ; } if ( writer . nrtIsCurrent ( segmentInfos ) ) { return null ; } IndexReader reader = writer . getReader ( applyAllDeletes ) ; <START_BUG> if ( ( reader . getVersion ( ) ) == ( getVersion ( ) ) ) { <END_BUG> reader . decRef ( ) ; return null ; } reader . readerFinishedListeners = readerFinishedListeners ; return reader ; } private IndexReader doOpenIfChanged ( final boolean openReadOnly , IndexCommit commit ) throws IOException , CorruptIndexException { } private synchronized IndexReader doOpenNoWriter ( final boolean openReadOnly , IndexCommit commit ) throws IOException , CorruptIndexException { } private synchronized DirectoryReader doOpenIfChanged ( 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 { } void startCommit ( ) { } void rollbackCommit ( ) { } @ Override public long getUniqueTermCount ( ) throws IOException { } @ Override public Map < String , String > getCommitUserData ( ) { } @ Override public boolean isCurrent ( ) throws IOException , CorruptIndexException { } @ Override protected synchronized void doClose ( ) throws IOException { } @ Override public Collection < String > getFieldNames ( IndexReader . FieldOption fieldNames ) { } static Collection < String > getFieldNames ( IndexReader . FieldOption fieldNames , IndexReader [ ] subReaders ) { } @ Override public ReaderContext getTopReaderContext ( ) { } @ Override public IndexReader [ ] getSequentialSubReaders ( ) { } @ Override public Directory directory ( ) { } @ Override public int getTermInfosIndexDivisor ( ) { } @ Override public IndexCommit getIndexCommit ( ) throws IOException { } public static List < IndexCommit > listCommits ( Directory dir ) throws IOException { } public static List < IndexCommit > listCommits ( Directory dir , CodecProvider codecs ) throws IOException { } private static final class ReaderCommit extends IndexCommit { private String segmentsFileName ; Collection < String > files ;

Fix:
if ( ( reader . getVersion ( ) ) == ( segmentInfos . getVersion ( ) ) ) {