Buggy code:
final class DocumentsWriterFlushControl implements MemoryController { private final long hardMaxBytesPerDWPT ; private long activeBytes = 0 ; private long flushBytes = 0 ; private volatile int numPending = 0 ; final AtomicBoolean flushDeletes = new AtomicBoolean ( false ) ; private boolean fullFlush = false ; private final Queue < DocumentsWriterPerThread > flushQueue = new LinkedList < DocumentsWriterPerThread > ( ) ; private final Queue < DocumentsWriterFlushControl . BlockedFlush > blockedFlushes = new LinkedList < DocumentsWriterFlushControl . BlockedFlush > ( ) ; private final IdentityHashMap < DocumentsWriterPerThread , Long > flushingWriters = new IdentityHashMap < DocumentsWriterPerThread , Long > ( ) ; double maxConfiguredRamBuffer = 0 ; long peakActiveBytes = 0 ; long peakFlushBytes = 0 ; long peakNetBytes = 0 ; long peakDelta = 0 ; final DocumentsWriterStallControl stallControl ; private final DocumentsWriterPerThreadPool perThreadPool ; private final FlushPolicy flushPolicy ; private boolean closed = false ; private final DocumentsWriter documentsWriter ; private final IndexWriterConfig config ; DocumentsWriterFlushControl ( DocumentsWriter documentsWriter , IndexWriterConfig config ) { } public synchronized long activeBytes ( ) { } public synchronized long flushBytes ( ) { } public synchronized long netBytes ( ) { } public long stallLimitBytes ( ) { } private boolean assertMemory ( ) { } private void commitPerThreadBytes ( ThreadState perThread ) { } private boolean updatePeaks ( long delta ) { } synchronized DocumentsWriterPerThread doAfterDocument ( ThreadState perThread , boolean isUpdate ) { } synchronized void doAfterFlush ( DocumentsWriterPerThread dwpt ) { } public synchronized void waitForFlush ( ) { } public synchronized void setFlushPending ( ThreadState perThread ) { } synchronized void doOnAbort ( ThreadState state ) { } synchronized DocumentsWriterPerThread tryCheckoutForFlush ( ThreadState perThread ) { } private void checkoutAndBlock ( ThreadState perThread ) { } private DocumentsWriterPerThread internalTryCheckOutForFlush ( ThreadState perThread ) { } @ Override public String toString ( ) { } DocumentsWriterPerThread nextPendingFlush ( ) { } synchronized void setClosed ( ) { } public Iterator < ThreadState > allActiveThreadStates ( ) { } private Iterator < ThreadState > getPerThreadsIterator ( final int upto ) { } synchronized void doOnDelete ( ) { } public int getNumGlobalTermDeletes ( ) { } public long getDeleteBytesUsed ( ) { } synchronized int numFlushingDWPT ( ) { } public boolean doApplyAllDeletes ( ) { } public void setApplyAllDeletes ( ) { } int numActiveDWPT ( ) { } ThreadState obtainAndLock ( ) { } void markForFullFlush ( ) { } private boolean assertActiveDeleteQueue ( DocumentsWriterDeleteQueue queue ) { } private final List < DocumentsWriterPerThread > fullFlushBuffer = new ArrayList < DocumentsWriterPerThread > ( ) ; void addFlushableState ( ThreadState perThread ) { if ( documentsWriter . infoStream . isEnabled ( "DWFC" ) ) { <START_BUG> documentsWriter . infoStream . message ( "DWFC" , ( ( ( Thread . currentThread ( ) . getName ( ) ) + ":<seq2seq4repair_space>addFlushableState<seq2seq4repair_space>" ) + ( perThread . dwpt ) ) ) ; <END_BUG> } final DocumentsWriterPerThread dwpt = perThread . dwpt ; assert perThread . isHeldByCurrentThread ( ) ; assert perThread . isActive ( ) ; assert fullFlush ; assert ( dwpt . deleteQueue ) != ( documentsWriter . deleteQueue ) ; if ( ( dwpt . getNumDocsInRAM ( ) ) > 0 ) { synchronized ( this ) { if ( ! ( perThread . flushPending ) ) { setFlushPending ( perThread ) ; } final DocumentsWriterPerThread flushingDWPT = internalTryCheckOutForFlush ( perThread ) ; assert flushingDWPT != null : "DWPT<seq2seq4repair_space>must<seq2seq4repair_space>never<seq2seq4repair_space>be<seq2seq4repair_space>null<seq2seq4repair_space>here<seq2seq4repair_space>since<seq2seq4repair_space>we<seq2seq4repair_space>hold<seq2seq4repair_space>the<seq2seq4repair_space>lock<seq2seq4repair_space>and<seq2seq4repair_space>it<seq2seq4repair_space>holds<seq2seq4repair_space>documents" ; assert dwpt == flushingDWPT : "flushControl<seq2seq4repair_space>returned<seq2seq4repair_space>different<seq2seq4repair_space>DWPT" ; fullFlushBuffer . add ( flushingDWPT ) ; } } else { if ( closed ) { perThreadPool . deactivateThreadState ( perThread ) ; } else { perThreadPool . reinitThreadState ( perThread ) ; } } } private void pruneBlockedQueue ( final DocumentsWriterDeleteQueue flushingQueue ) { } synchronized void finishFullFlush ( ) { } boolean assertBlockedFlushes ( DocumentsWriterDeleteQueue flushingQueue ) { } synchronized void abortFullFlushes ( ) { } synchronized boolean isFullFlush ( ) { } synchronized int numQueuedFlushes ( ) { } synchronized int numBlockedFlushes ( ) { } private static class BlockedFlush { final DocumentsWriterPerThread dwpt ; final long bytes ; BlockedFlush ( DocumentsWriterPerThread dwpt , long bytes ) { } } void waitIfStalled ( ) { } boolean anyStalledThreads ( ) { } }

Fix:
documentsWriter . infoStream . message ( "DWFC" , ( "addFlushableState<seq2seq4repair_space>" + ( perThread . dwpt ) ) ) ;