Buggy code:
public class TestTermVectors extends LuceneTestCase { private static IndexSearcher searcher ; private static IndexReader reader ; private static Directory directory ; @ BeforeClass public static void beforeClass ( ) throws Exception { } @ AfterClass public static void afterClass ( ) throws Exception { } public void test ( ) { } public void testTermVectors ( ) throws IOException { } public void testTermVectorsFieldOrder ( ) throws IOException { } public void testTermPositionVectors ( ) throws IOException { } public void testTermOffsetVectors ( ) throws IOException { } public void testKnownSetOfDocuments ( ) throws IOException { String test1 = "eating<seq2seq4repair_space>chocolate<seq2seq4repair_space>in<seq2seq4repair_space>a<seq2seq4repair_space>computer<seq2seq4repair_space>lab" ; String test2 = "computer<seq2seq4repair_space>in<seq2seq4repair_space>a<seq2seq4repair_space>computer<seq2seq4repair_space>lab" ; String test3 = "a<seq2seq4repair_space>chocolate<seq2seq4repair_space>lab<seq2seq4repair_space>grows<seq2seq4repair_space>old" ; String test4 = "eating<seq2seq4repair_space>chocolate<seq2seq4repair_space>with<seq2seq4repair_space>a<seq2seq4repair_space>chocolate<seq2seq4repair_space>lab<seq2seq4repair_space>in<seq2seq4repair_space>an<seq2seq4repair_space>old<seq2seq4repair_space>chocolate<seq2seq4repair_space>colored<seq2seq4repair_space>computer<seq2seq4repair_space>lab" ; Map < String , Integer > test4Map = new HashMap < String , Integer > ( ) ; test4Map . put ( "chocolate" , Integer . valueOf ( 3 ) ) ; test4Map . put ( "lab" , Integer . valueOf ( 2 ) ) ; test4Map . put ( "eating" , Integer . valueOf ( 1 ) ) ; test4Map . put ( "computer" , Integer . valueOf ( 1 ) ) ; test4Map . put ( "with" , Integer . valueOf ( 1 ) ) ; test4Map . put ( "a" , Integer . valueOf ( 1 ) ) ; test4Map . put ( "colored" , Integer . valueOf ( 1 ) ) ; test4Map . put ( "in" , Integer . valueOf ( 1 ) ) ; test4Map . put ( "an" , Integer . valueOf ( 1 ) ) ; test4Map . put ( "computer" , Integer . valueOf ( 1 ) ) ; test4Map . put ( "old" , Integer . valueOf ( 1 ) ) ; Document testDoc1 = new Document ( ) ; setupDoc ( testDoc1 , test1 ) ; Document testDoc2 = new Document ( ) ; setupDoc ( testDoc2 , test2 ) ; Document testDoc3 = new Document ( ) ; setupDoc ( testDoc3 , test3 ) ; Document testDoc4 = new Document ( ) ; setupDoc ( testDoc4 , test4 ) ; Directory dir = newDirectory ( ) ; RandomIndexWriter writer = new RandomIndexWriter ( random ( ) , dir , newIndexWriterConfig ( TEST_VERSION_CURRENT , new org . apache . lucene . analysis . MockAnalyzer ( random ( ) , MockTokenizer . SIMPLE , true ) ) . setOpenMode ( CREATE ) . setMergePolicy ( newLogMergePolicy ( ) ) . setSimilarity ( new DefaultSimilarity ( ) ) ) ; writer . addDocument ( testDoc1 ) ; writer . addDocument ( testDoc2 ) ; writer . addDocument ( testDoc3 ) ; writer . addDocument ( testDoc4 ) ; IndexReader reader = writer . getReader ( ) ; writer . close ( ) ; IndexSearcher knownSearcher = newSearcher ( reader ) ; knownSearcher . setSimilarity ( new DefaultSimilarity ( ) ) ; FieldsEnum fields = MultiFields . getFields ( knownSearcher . reader ) . iterator ( ) ; DocsEnum docs = null ; while ( ( fields . next ( ) ) != null ) { Terms terms = fields . terms ( ) ; assertNotNull ( terms ) ; TermsEnum termsEnum = terms . iterator ( null ) ; while ( ( termsEnum . next ( ) ) != null ) { String text = termsEnum . term ( ) . utf8ToString ( ) ; <START_BUG> docs = _TestUtil . docs ( random ( ) , termsEnum , MultiFields . getLiveDocs ( knownSearcher . reader ) , docs , FLAG_FREQS ) ; <END_BUG> while ( ( docs . nextDoc ( ) ) != ( DocIdSetIterator . NO_MORE_DOCS ) ) { int docId = docs . docID ( ) ; int freq = docs . freq ( ) ; Terms vector = knownSearcher . reader . getTermVectors ( docId ) . terms ( "field" ) ; assertNotNull ( vector ) ; TermsEnum termsEnum2 = vector . iterator ( null ) ; while ( ( termsEnum2 . next ( ) ) != null ) { if ( text . equals ( termsEnum2 . term ( ) . utf8ToString ( ) ) ) { assertEquals ( freq , termsEnum2 . totalTermFreq ( ) ) ; } } } } } Query query = new TermQuery ( new Term ( "field" , "chocolate" ) ) ; ScoreDoc [ ] hits = knownSearcher . search ( query , null , 1000 ) . scoreDocs ; assertTrue ( ( ( hits . length ) == 3 ) ) ; assertTrue ( ( ( hits [ 0 ] . doc ) == 2 ) ) ; assertTrue ( ( ( hits [ 1 ] . doc ) == 3 ) ) ; assertTrue ( ( ( hits [ 2 ] . doc ) == 0 ) ) ; Terms vector = knownSearcher . reader . getTermVectors ( hits [ 1 ] . doc ) . terms ( "field" ) ; assertNotNull ( vector ) ; assertEquals ( 10 , vector . size ( ) ) ; TermsEnum termsEnum = vector . iterator ( null ) ; while ( ( termsEnum . next ( ) ) != null ) { String term = termsEnum . term ( ) . utf8ToString ( ) ; int freq = ( ( int ) ( termsEnum . totalTermFreq ( ) ) ) ; assertTrue ( ( ( test4 . indexOf ( term ) ) != ( - 1 ) ) ) ; Integer freqInt = test4Map . get ( term ) ; assertTrue ( ( freqInt != null ) ) ; assertEquals ( freqInt . intValue ( ) , freq ) ; } reader . close ( ) ; dir . close ( ) ; } private void setupDoc ( Document doc , String text ) { } public void testRareVectors ( ) throws IOException { } public void testMixedVectrosVectors ( ) throws IOException { } private IndexWriter createWriter ( Directory dir ) throws IOException { }

Fix:
docs = _TestUtil . docs ( random ( ) , termsEnum , MultiFields . getLiveDocs ( knownSearcher . reader ) , docs , true ) ;