Buggy code:
class DirectoryReader extends IndexReader implements Cloneable { protected Directory directory ; 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 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 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 { } void startCommit ( ) { } void rollbackCommit ( ) { } @ 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 IndexReader [ ] getSequentialSubReaders ( ) { } @ Override public Directory directory ( ) { } @ Override public int getTermInfosIndexDivisor ( ) { }

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