Buggy code:
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 ( ) { } } 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 { Directory dir = newDirectory ( ) ; IndexWriterConfig conf = newIndexWriterConfig ( TEST_VERSION_CURRENT , new Analyzer ( ) { @ Override public TokenStreamComponents createComponents ( String fieldName , Reader reader ) { MockTokenizer tokenizer = new MockTokenizer ( reader , MockTokenizer . SIMPLE , true ) ; tokenizer . setEnableChecks ( false ) ; return new TokenStreamComponents ( tokenizer , new TokenFilter ( tokenizer ) { private int count = 0 ; @ Override public boolean incrementToken ( ) throws IOException { if ( ( ( count ) ++ ) == 5 ) { throw new IOException ( ) ; } return input . incrementToken ( ) ; } @ Override public void reset ( ) throws IOException { super . reset ( ) ; this . count = 0 ; } } ) ; } } ) ; conf . setMaxBufferedDocs ( Math . max ( 3 , conf . getMaxBufferedDocs ( ) ) ) ; IndexWriter writer = new IndexWriter ( dir , conf ) ; Document doc = new Document ( ) ; String contents = "aa<seq2seq4repair_space>bb<seq2seq4repair_space>cc<seq2seq4repair_space>dd<seq2seq4repair_space>ee<seq2seq4repair_space>ff<seq2seq4repair_space>gg<seq2seq4repair_space>hh<seq2seq4repair_space>ii<seq2seq4repair_space>jj<seq2seq4repair_space>kk" ; doc . add ( newTextField ( "content" , contents , NO ) ) ; try { writer . addDocument ( doc ) ; fail ( "did<seq2seq4repair_space>not<seq2seq4repair_space>hit<seq2seq4repair_space>expected<seq2seq4repair_space>exception" ) ; } catch ( Exception e ) { } doc = new Document ( ) ; doc . add ( newTextField ( "content" , "aa<seq2seq4repair_space>bb<seq2seq4repair_space>cc<seq2seq4repair_space>dd" , NO ) ) ; writer . addDocument ( doc ) ; doc = new Document ( ) ; doc . add ( newTextField ( "content" , "aa<seq2seq4repair_space>bb<seq2seq4repair_space>cc<seq2seq4repair_space>dd" , NO ) ) ; writer . addDocument ( doc ) ; writer . close ( ) ; IndexReader reader = DirectoryReader . open ( dir ) ; final Term t = new Term ( "content" , "aa" ) ; assertEquals ( 3 , reader . docFreq ( t ) ) ; <START_BUG> DocsEnum tdocs = _TestUtil . docs ( random ( ) , reader , t . field ( ) , new org . apache . lucene . util . BytesRef ( t . text ( ) ) , MultiFields . getLiveDocs ( reader ) , null , false ) ; <END_BUG> int count = 0 ; while ( ( tdocs . nextDoc ( ) ) != ( DocIdSetIterator . NO_MORE_DOCS ) ) { count ++ ; } assertEquals ( 2 , count ) ; assertEquals ( reader . docFreq ( new Term ( "content" , "gg" ) ) , 0 ) ; reader . close ( ) ; dir . close ( ) ; } 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 { } public void testDocumentsWriterExceptionThreads ( ) throws Exception { } private static class FailOnlyInSync extends MockDirectoryWrapper . Failure { boolean didFail ; @ Override public void eval ( MockDirectoryWrapper dir ) throws IOException { } } private void addDoc ( IndexWriter writer ) throws IOException { } public void testExceptionDuringSync ( ) throws IOException { } private static class FailOnlyInCommit extends MockDirectoryWrapper . Failure { boolean failOnCommit ; boolean failOnDeleteFile ; private final boolean dontFailDuringGlobalFieldMap ; private static final String PREPARE_STAGE = "prepareCommit" ; private static final String FINISH_STAGE = "finishCommit" ; private final String stage ; public FailOnlyInCommit ( boolean dontFailDuringGlobalFieldMap , String stage ) { } @ Override public void eval ( MockDirectoryWrapper dir ) throws IOException { } } public void testExceptionsDuringCommit ( ) throws Throwable { } public void testForceMergeExceptions ( ) throws IOException { } public void testOutOfMemoryErrorCausesCloseToFail ( ) throws Exception { } private static final class MockIndexWriter4 extends IndexWriter { public MockIndexWriter4 ( Directory dir , IndexWriterConfig conf ) throws IOException { } boolean doFail ;

Fix:
DocsEnum tdocs = _TestUtil . docs ( random ( ) , reader , t . field ( ) , new org . apache . lucene . util . BytesRef ( t . text ( ) ) , MultiFields . getLiveDocs ( reader ) , null , 0 ) ;