Buggy code:
} 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 { } 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 ; @ Override boolean testPoint ( String name ) { } } public void testRollbackExceptionHang ( ) throws Throwable { } public void testSegmentsChecksumError ( ) throws IOException { } public void testSimulatedCorruptIndex1 ( ) throws IOException { } public void testSimulatedCorruptIndex2 ( ) throws IOException { } public void testSimulatedCrashedWriter ( ) throws IOException { } public void testTermVectorExceptions ( ) throws IOException { TestIndexWriterExceptions . FailOnTermVectors [ ] failures = new TestIndexWriterExceptions . FailOnTermVectors [ ] { new TestIndexWriterExceptions . FailOnTermVectors ( TestIndexWriterExceptions . FailOnTermVectors . AFTER_INIT_STAGE ) , new TestIndexWriterExceptions . FailOnTermVectors ( TestIndexWriterExceptions . FailOnTermVectors . INIT_STAGE ) } ; int num = atLeast ( 1 ) ; for ( int j = 0 ; j < num ; j ++ ) { for ( TestIndexWriterExceptions . FailOnTermVectors failure : failures ) { MockDirectoryWrapper dir = newMockDirectory ( ) ; IndexWriter w = new IndexWriter ( dir , newIndexWriterConfig ( TEST_VERSION_CURRENT , new MockAnalyzer ( random ( ) ) ) ) ; dir . failOn ( failure ) ; int numDocs = 10 + ( random ( ) . nextInt ( 30 ) ) ; for ( int i = 0 ; i < numDocs ; i ++ ) { Document doc = new Document ( ) ; Field field = newTextField ( random ( ) , "field" , "a<seq2seq4repair_space>field" , YES ) ; doc . add ( field ) ; try { w . addDocument ( doc ) ; assertFalse ( field . fieldType ( ) . storeTermVectors ( ) ) ; } catch ( RuntimeException e ) { assertTrue ( e . getMessage ( ) . startsWith ( TestIndexWriterExceptions . FailOnTermVectors . EXC_MSG ) ) ; } if ( ( random ( ) . nextInt ( 20 ) ) == 0 ) { w . commit ( ) ; _TestUtil . checkIndex ( dir ) ; } } Document document = new Document ( ) ; document . add ( new TextField ( "field" , "a<seq2seq4repair_space>field" , Store . YES ) ) ; w . addDocument ( document ) ; for ( int i = 0 ; i < numDocs ; i ++ ) { Document doc = new Document ( ) ; Field field = newTextField ( random ( ) , "field" , "a<seq2seq4repair_space>field" , YES ) ; doc . add ( field ) ; try { w . addDocument ( doc ) ; assertFalse ( field . fieldType ( ) . storeTermVectors ( ) ) ; } catch ( RuntimeException e ) { assertTrue ( e . getMessage ( ) . startsWith ( TestIndexWriterExceptions . FailOnTermVectors . EXC_MSG ) ) ; } if ( ( random ( ) . nextInt ( 20 ) ) == 0 ) { w . commit ( ) ; _TestUtil . checkIndex ( dir ) ; } } document = new Document ( ) ; document . add ( new TextField ( "field" , "a<seq2seq4repair_space>field" , Store . YES ) ) ; w . addDocument ( document ) ; w . close ( ) ; IndexReader reader = DirectoryReader . open ( dir ) ; assertTrue ( ( ( reader . numDocs ( ) ) > 0 ) ) ; SegmentInfos sis = new SegmentInfos ( ) ; sis . read ( dir ) ; <START_BUG> for ( AtomicReaderContext context : reader . getTopReaderContext ( ) . leaves ( ) ) { <END_BUG> assertFalse ( context . reader ( ) . getFieldInfos ( ) . hasVectors ( ) ) ; } reader . close ( ) ; dir . close ( ) ; } } } private static class FailOnTermVectors extends MockDirectoryWrapper . Failure { private static final String INIT_STAGE = "initTermVectorsWriter" ; private static final String AFTER_INIT_STAGE = "finishDocument" ; private static final String EXC_MSG = "FOTV" ; private final String stage ; public FailOnTermVectors ( String stage ) { } @ Override public void eval ( MockDirectoryWrapper dir ) throws IOException { } } public void testAddDocsNonAbortingException ( ) throws Exception { } public void testUpdateDocsNonAbortingException ( ) throws Exception { } static class UOEDirectory extends RAMDirectory { boolean doFail = false ; @ Override public IndexInput openInput ( String name , IOContext context ) throws IOException { } } public void testExceptionOnCtor ( ) throws Exception { } public void testIllegalPositions ( ) throws Exception { } public void testLegalbutVeryLargePositions ( ) throws Exception { } public void testBoostOmitNorms ( ) throws Exception { } }

Fix:
for ( AtomicReaderContext context : reader . leaves ( ) ) {