Buggy code:
assertTrue ( "tve<seq2seq4repair_space>is<seq2seq4repair_space>null<seq2seq4repair_space>and<seq2seq4repair_space>it<seq2seq4repair_space>shouldn't<seq2seq4repair_space>be" , ( tve != null ) ) ; assertTrue ( "tve.getOffsets()<seq2seq4repair_space>is<seq2seq4repair_space>null<seq2seq4repair_space>and<seq2seq4repair_space>it<seq2seq4repair_space>shouldn't<seq2seq4repair_space>be" , ( ( tve . getOffsets ( ) ) != null ) ) ; assertTrue ( "tve.getPositions()<seq2seq4repair_space>is<seq2seq4repair_space>null<seq2seq4repair_space>and<seq2seq4repair_space>it<seq2seq4repair_space>shouldn't<seq2seq4repair_space>be" , ( ( tve . getPositions ( ) ) != null ) ) ; } FieldSortedTermVectorMapper fsMapper = new FieldSortedTermVectorMapper ( new TermVectorEntryFreqSortedComparator ( ) ) ; reader . get ( 0 , fsMapper ) ; Map map = fsMapper . getFieldToTerms ( ) ; assertTrue ( ( ( ( "map<seq2seq4repair_space>Size:<seq2seq4repair_space>" + ( map . size ( ) ) ) + "<seq2seq4repair_space>is<seq2seq4repair_space>not:<seq2seq4repair_space>" ) + ( testFields . length ) ) , ( ( map . size ( ) ) == ( testFields . length ) ) ) ; for ( Iterator iterator = map . entrySet ( ) . iterator ( ) ; iterator . hasNext ( ) ; ) { Map . Entry entry = ( ( Map . Entry ) ( iterator . next ( ) ) ) ; SortedSet sortedSet = ( ( SortedSet ) ( entry . getValue ( ) ) ) ; assertTrue ( ( ( ( "sortedSet<seq2seq4repair_space>Size:<seq2seq4repair_space>" + ( sortedSet . size ( ) ) ) + "<seq2seq4repair_space>is<seq2seq4repair_space>not:<seq2seq4repair_space>" ) + 4 ) , ( ( sortedSet . size ( ) ) == 4 ) ) ; for ( Iterator inner = sortedSet . iterator ( ) ; inner . hasNext ( ) ; ) { TermVectorEntry tve = ( ( TermVectorEntry ) ( inner . next ( ) ) ) ; assertTrue ( "tve<seq2seq4repair_space>is<seq2seq4repair_space>null<seq2seq4repair_space>and<seq2seq4repair_space>it<seq2seq4repair_space>shouldn't<seq2seq4repair_space>be" , ( tve != null ) ) ; assertTrue ( "tve<seq2seq4repair_space>is<seq2seq4repair_space>null<seq2seq4repair_space>and<seq2seq4repair_space>it<seq2seq4repair_space>shouldn't<seq2seq4repair_space>be" , ( tve != null ) ) ; String field = tve . getField ( ) ; if ( field . equals ( testFields [ 0 ] ) ) { assertTrue ( "tve.getOffsets()<seq2seq4repair_space>is<seq2seq4repair_space>null<seq2seq4repair_space>and<seq2seq4repair_space>it<seq2seq4repair_space>shouldn't<seq2seq4repair_space>be" , ( ( tve . getOffsets ( ) ) != null ) ) ; assertTrue ( "tve.getPositions()<seq2seq4repair_space>is<seq2seq4repair_space>null<seq2seq4repair_space>and<seq2seq4repair_space>it<seq2seq4repair_space>shouldn't<seq2seq4repair_space>be" , ( ( tve . getPositions ( ) ) != null ) ) ; } else if ( field . equals ( testFields [ 1 ] ) ) { assertTrue ( "tve.getOffsets()<seq2seq4repair_space>is<seq2seq4repair_space>not<seq2seq4repair_space>null<seq2seq4repair_space>and<seq2seq4repair_space>it<seq2seq4repair_space>shouldn't<seq2seq4repair_space>be" , ( ( tve . getOffsets ( ) ) == null ) ) ; assertTrue ( "tve.getPositions()<seq2seq4repair_space>is<seq2seq4repair_space>not<seq2seq4repair_space>null<seq2seq4repair_space>and<seq2seq4repair_space>it<seq2seq4repair_space>shouldn't<seq2seq4repair_space>be" , ( ( tve . getPositions ( ) ) == null ) ) ; } } } fsMapper = new FieldSortedTermVectorMapper ( true , true , new TermVectorEntryFreqSortedComparator ( ) ) ; reader . get ( 0 , fsMapper ) ; map = fsMapper . getFieldToTerms ( ) ; assertTrue ( ( ( ( "map<seq2seq4repair_space>Size:<seq2seq4repair_space>" + ( map . size ( ) ) ) + "<seq2seq4repair_space>is<seq2seq4repair_space>not:<seq2seq4repair_space>" ) + ( testFields . length ) ) , ( ( map . size ( ) ) == ( testFields . length ) ) ) ; for ( Iterator iterator = map . entrySet ( ) . iterator ( ) ; iterator . hasNext ( ) ; ) { Map . Entry entry = ( ( Map . Entry ) ( iterator . next ( ) ) ) ; SortedSet sortedSet = ( ( SortedSet ) ( entry . getValue ( ) ) ) ; assertTrue ( ( ( ( "sortedSet<seq2seq4repair_space>Size:<seq2seq4repair_space>" + ( sortedSet . size ( ) ) ) + "<seq2seq4repair_space>is<seq2seq4repair_space>not:<seq2seq4repair_space>" ) + 4 ) , ( ( sortedSet . size ( ) ) == 4 ) ) ; for ( Iterator inner = sortedSet . iterator ( ) ; inner . hasNext ( ) ; ) { TermVectorEntry tve = ( ( TermVectorEntry ) ( inner . next ( ) ) ) ; assertTrue ( "tve<seq2seq4repair_space>is<seq2seq4repair_space>null<seq2seq4repair_space>and<seq2seq4repair_space>it<seq2seq4repair_space>shouldn't<seq2seq4repair_space>be" , ( tve != null ) ) ; assertTrue ( "tve<seq2seq4repair_space>is<seq2seq4repair_space>null<seq2seq4repair_space>and<seq2seq4repair_space>it<seq2seq4repair_space>shouldn't<seq2seq4repair_space>be" , ( tve != null ) ) ; String field = tve . getField ( ) ; if ( field . equals ( testFields [ 0 ] ) ) { assertTrue ( "tve.getOffsets()<seq2seq4repair_space>is<seq2seq4repair_space>null<seq2seq4repair_space>and<seq2seq4repair_space>it<seq2seq4repair_space>shouldn't<seq2seq4repair_space>be" , ( ( tve . getOffsets ( ) ) == null ) ) ; assertTrue ( "tve.getPositions()<seq2seq4repair_space>is<seq2seq4repair_space>null<seq2seq4repair_space>and<seq2seq4repair_space>it<seq2seq4repair_space>shouldn't<seq2seq4repair_space>be" , ( ( tve . getPositions ( ) ) == null ) ) ; } else if ( field . equals ( testFields [ 1 ] ) ) { assertTrue ( "tve.getOffsets()<seq2seq4repair_space>is<seq2seq4repair_space>not<seq2seq4repair_space>null<seq2seq4repair_space>and<seq2seq4repair_space>it<seq2seq4repair_space>shouldn't<seq2seq4repair_space>be" , ( ( tve . getOffsets ( ) ) == null ) ) ; assertTrue ( "tve.getPositions()<seq2seq4repair_space>is<seq2seq4repair_space>not<seq2seq4repair_space>null<seq2seq4repair_space>and<seq2seq4repair_space>it<seq2seq4repair_space>shouldn't<seq2seq4repair_space>be" , ( ( tve . getPositions ( ) ) == null ) ) ; } } } <START_BUG> IndexReader ir = IndexReader . open ( dir ) ; <END_BUG> TestTermVectorsReader . DocNumAwareMapper docNumAwareMapper = new TestTermVectorsReader . DocNumAwareMapper ( ) ; assertEquals ( ( - 1 ) , docNumAwareMapper . getDocumentNumber ( ) ) ; ir . getTermFreqVector ( 0 , docNumAwareMapper ) ; assertEquals ( 0 , docNumAwareMapper . getDocumentNumber ( ) ) ; docNumAwareMapper . setDocumentNumber ( ( - 1 ) ) ; ir . getTermFreqVector ( 1 , docNumAwareMapper ) ; assertEquals ( 1 , docNumAwareMapper . getDocumentNumber ( ) ) ; docNumAwareMapper . setDocumentNumber ( ( - 1 ) ) ; ir . getTermFreqVector ( 0 , "f1" , docNumAwareMapper ) ; assertEquals ( 0 , docNumAwareMapper . getDocumentNumber ( ) ) ; docNumAwareMapper . setDocumentNumber ( ( - 1 ) ) ; ir . getTermFreqVector ( 1 , "f2" , docNumAwareMapper ) ; assertEquals ( 1 , docNumAwareMapper . getDocumentNumber ( ) ) ; docNumAwareMapper . setDocumentNumber ( ( - 1 ) ) ; ir . getTermFreqVector ( 0 , "f1" , docNumAwareMapper ) ; assertEquals ( 0 , docNumAwareMapper . getDocumentNumber ( ) ) ; ir . close ( ) ; } public void testBadParams ( ) { } public static class DocNumAwareMapper extends TermVectorMapper { public DocNumAwareMapper ( ) { } private int documentNumber = - 1 ; public void setExpectations ( String field , int numTerms , boolean storeOffsets , boolean storePositions ) { } public void map ( String term , int frequency , TermVectorOffsetInfo [ ] offsets , int [ ] positions ) { } public int getDocumentNumber ( ) { } public void setDocumentNumber ( int documentNumber ) { }

Fix:
IndexReader ir = IndexReader . open ( dir , true ) ;