Buggy code:
public class TestIndexWriterNRTIsCurrent extends LuceneTestCase { public static class ReaderHolder { volatile DirectoryReader reader ; volatile boolean stop = false ; } public void testIsCurrentWithThreads ( ) throws IOException , InterruptedException , CorruptIndexException , LockObtainFailedException { } public static class WriterThread extends Thread { private final TestIndexWriterNRTIsCurrent . ReaderHolder holder ; private final IndexWriter writer ; private final int numOps ; private boolean countdown = true ; private final CountDownLatch latch ; Throwable failed ; WriterThread ( TestIndexWriterNRTIsCurrent . ReaderHolder holder , IndexWriter writer , int numOps , Random random , CountDownLatch latch ) { } public void run ( ) { DirectoryReader currentReader = null ; Random random = LuceneTestCase . random ( ) ; try { Document doc = new Document ( ) ; <START_BUG> doc . add ( new org . apache . lucene . document . Field ( "id" , "1" , TextField . TYPE_UNSTORED ) ) ; <END_BUG> writer . addDocument ( doc ) ; holder . reader = currentReader = writer . getReader ( true ) ; Term term = new Term ( "id" ) ; for ( int i = 0 ; ( i < ( numOps ) ) && ( ! ( holder . stop ) ) ; i ++ ) { float nextOp = random . nextFloat ( ) ; if ( nextOp < 0.3 ) { term . set ( "id" , new BytesRef ( "1" ) ) ; writer . updateDocument ( term , doc ) ; } else if ( nextOp < 0.5 ) { writer . addDocument ( doc ) ; } else { term . set ( "id" , new BytesRef ( "1" ) ) ; writer . deleteDocuments ( term ) ; } if ( ( holder . reader ) != currentReader ) { holder . reader = currentReader ; if ( countdown ) { countdown = false ; latch . countDown ( ) ; } } if ( random . nextBoolean ( ) ) { writer . commit ( ) ; final DirectoryReader newReader = DirectoryReader . openIfChanged ( currentReader ) ; if ( newReader != null ) { currentReader . decRef ( ) ; currentReader = newReader ; } if ( ( currentReader . numDocs ( ) ) == 0 ) { writer . addDocument ( doc ) ; } } } } catch ( Throwable e ) { failed = e ; } finally { holder . reader = null ; if ( countdown ) { latch . countDown ( ) ; } if ( currentReader != null ) { try { currentReader . decRef ( ) ; } catch ( IOException e ) { } } } if ( VERBOSE ) { System . out . println ( ( "writer<seq2seq4repair_space>stopped<seq2seq4repair_space>-<seq2seq4repair_space>forced<seq2seq4repair_space>by<seq2seq4repair_space>reader:<seq2seq4repair_space>" + ( holder . stop ) ) ) ; } } } public static final class ReaderThread extends Thread { private final TestIndexWriterNRTIsCurrent . ReaderHolder holder ; private final CountDownLatch latch ; Throwable failed ; ReaderThread ( TestIndexWriterNRTIsCurrent . ReaderHolder holder , CountDownLatch latch ) { } public void run ( ) { try { latch . await ( ) ; } catch ( InterruptedException e ) { failed = e ; return ; } DirectoryReader reader ; while ( ( reader = holder . reader ) != null ) { if ( reader . tryIncRef ( ) ) { try { boolean current = reader . isCurrent ( ) ; if ( VERBOSE ) { System . out . println ( ( ( ( ( ( "Thread:<seq2seq4repair_space>" + ( Thread . currentThread ( ) ) ) + "<seq2seq4repair_space>Reader:<seq2seq4repair_space>" ) + reader ) + "<seq2seq4repair_space>isCurrent:" ) + current ) ) ; } assertFalse ( current ) ; } catch ( Throwable e ) { if ( VERBOSE ) { System . out . println ( ( ( ( ( "FAILED<seq2seq4repair_space>Thread:<seq2seq4repair_space>" + ( Thread . currentThread ( ) ) ) + "<seq2seq4repair_space>Reader:<seq2seq4repair_space>" ) + reader ) + "<seq2seq4repair_space>isCurrent:<seq2seq4repair_space>false" ) ) ; } failed = e ; holder . stop = true ; return ; } finally { try { reader . decRef ( ) ; } catch ( IOException e ) { if ( ( failed ) == null ) { failed = e ; } return ; } } } } } } }

Fix:
doc . add ( new org . apache . lucene . document . TextField ( "id" , "1" , Store . NO ) ) ;