Buggy code:
public class TestIndexWriterExceptions extends LuceneTestCase { private static class DocCopyIterator implements Iterable < Document > { private final Document doc ; private final int count ; private static final FieldType custom1 = new FieldType ( TextField . TYPE_UNSTORED ) ; private static final FieldType custom2 = new FieldType ( ) ; private static final FieldType custom3 = new FieldType ( ) ; private static final FieldType custom4 = new FieldType ( StringField . TYPE_UNSTORED ) ; private static final FieldType custom5 = new FieldType ( TextField . TYPE_STORED ) ; public DocCopyIterator ( Document doc , int count ) { } @ Override public Iterator < Document > iterator ( ) { } } private class IndexerThread extends Thread { IndexWriter writer ; final Random r = new Random ( random . nextLong ( ) ) ; volatile Throwable failure ; public IndexerThread ( int i , IndexWriter writer ) { } @ Override public void run ( ) { final Document doc = new Document ( ) ; doc . add ( newField ( r , "content1" , "aaa<seq2seq4repair_space>bbb<seq2seq4repair_space>ccc<seq2seq4repair_space>ddd" , TYPE_STORED ) ) ; doc . add ( newField ( r , "content6" , "aaa<seq2seq4repair_space>bbb<seq2seq4repair_space>ccc<seq2seq4repair_space>ddd" , TestIndexWriterExceptions . DocCopyIterator . custom1 ) ) ; doc . add ( newField ( r , "content2" , "aaa<seq2seq4repair_space>bbb<seq2seq4repair_space>ccc<seq2seq4repair_space>ddd" , TestIndexWriterExceptions . DocCopyIterator . custom2 ) ) ; doc . add ( newField ( r , "content3" , "aaa<seq2seq4repair_space>bbb<seq2seq4repair_space>ccc<seq2seq4repair_space>ddd" , TestIndexWriterExceptions . DocCopyIterator . custom3 ) ) ; doc . add ( newField ( r , "content4" , "aaa<seq2seq4repair_space>bbb<seq2seq4repair_space>ccc<seq2seq4repair_space>ddd" , TYPE_UNSTORED ) ) ; doc . add ( newField ( r , "content5" , "aaa<seq2seq4repair_space>bbb<seq2seq4repair_space>ccc<seq2seq4repair_space>ddd" , StringField . TYPE_UNSTORED ) ) ; doc . add ( newField ( r , "content7" , "aaa<seq2seq4repair_space>bbb<seq2seq4repair_space>ccc<seq2seq4repair_space>ddd" , TestIndexWriterExceptions . DocCopyIterator . custom4 ) ) ; final Field idField = newField ( r , "id" , "" , TestIndexWriterExceptions . DocCopyIterator . custom2 ) ; doc . add ( idField ) ; final long stopTime = ( System . currentTimeMillis ( ) ) + 500 ; do { if ( VERBOSE ) { System . out . println ( ( ( Thread . currentThread ( ) . getName ( ) ) + ":<seq2seq4repair_space>TEST:<seq2seq4repair_space>IndexerThread:<seq2seq4repair_space>cycle" ) ) ; } doFail . set ( this ) ; final String id = "" + ( r . nextInt ( 50 ) ) ; <START_BUG> idField . setValue ( id ) ; <END_BUG> Term idTerm = new Term ( "id" , id ) ; try { if ( r . nextBoolean ( ) ) { writer . updateDocuments ( idTerm , new TestIndexWriterExceptions . DocCopyIterator ( doc , _TestUtil . nextInt ( r , 1 , 20 ) ) ) ; } else { writer . updateDocument ( idTerm , doc ) ; } } catch ( RuntimeException re ) { if ( VERBOSE ) { System . out . println ( ( ( Thread . currentThread ( ) . getName ( ) ) + ":<seq2seq4repair_space>EXC:<seq2seq4repair_space>" ) ) ; re . printStackTrace ( System . out ) ; } try { _TestUtil . checkIndex ( writer . getDirectory ( ) ) ; } catch ( IOException ioe ) { System . out . println ( ( ( Thread . currentThread ( ) . getName ( ) ) + ":<seq2seq4repair_space>unexpected<seq2seq4repair_space>exception1" ) ) ; ioe . printStackTrace ( System . out ) ; failure = ioe ; break ; } } catch ( Throwable t ) { System . out . println ( ( ( Thread . currentThread ( ) . getName ( ) ) + ":<seq2seq4repair_space>unexpected<seq2seq4repair_space>exception2" ) ) ; t . printStackTrace ( System . out ) ; failure = t ; break ; } doFail . set ( null ) ; try { writer . updateDocument ( idTerm , doc ) ; } catch ( Throwable t ) { System . out . println ( ( ( Thread . currentThread ( ) . getName ( ) ) + ":<seq2seq4repair_space>unexpected<seq2seq4repair_space>exception3" ) ) ; t . printStackTrace ( System . out ) ; failure = t ; break ; } } while ( ( System . currentTimeMillis ( ) ) < stopTime ) ; } } ThreadLocal < Thread > doFail = new ThreadLocal < Thread > ( ) ; private class MockIndexWriter extends IndexWriter { Random r = new Random ( random . nextLong ( ) ) ; public MockIndexWriter ( Directory dir , IndexWriterConfig conf ) throws IOException { } @ Override boolean testPoint ( String name ) { } } public void testRandomExceptions ( ) throws Throwable { } public void testRandomExceptionsThreads ( ) throws Throwable { } private static final class MockIndexWriter2 extends IndexWriter { public MockIndexWriter2 ( Directory dir , IndexWriterConfig conf ) throws IOException { } boolean doFail ; @ Override boolean testPoint ( String name ) { } } private static String CRASH_FAIL_MESSAGE = "I'm<seq2seq4repair_space>experiencing<seq2seq4repair_space>problems" ; private class CrashingFilter extends TokenFilter { String fieldName ; int count ; public CrashingFilter ( String fieldName , TokenStream input ) { } @ Override public boolean incrementToken ( ) throws IOException { } @ Override public void reset ( ) throws IOException { } } public void testExceptionDocumentsWriterInit ( ) throws IOException { } public void testExceptionJustBeforeFlush ( ) throws IOException { } private static final class MockIndexWriter3 extends IndexWriter { public MockIndexWriter3 ( Directory dir , IndexWriterConfig conf ) throws IOException { } boolean doFail ; boolean failed ; @ Override boolean testPoint ( String name ) { } } public void testExceptionOnMergeInit ( ) throws IOException { } public void testExceptionFromTokenStream ( ) throws IOException { } private static class FailOnlyOnFlush extends MockDirectoryWrapper . Failure { boolean doFail = false ; int count ; @ Override public void setDoFail ( ) { } @ Override public void clearDoFail ( ) { } @ Override public void eval ( MockDirectoryWrapper dir ) throws IOException { } } public void testDocumentsWriterAbort ( ) throws IOException { } public void testDocumentsWriterExceptions ( ) throws IOException { }

Fix:
idField . setStringValue ( id ) ;