Buggy code:
public class TestSegmentMerger extends LuceneTestCase { private Directory mergedDir ; private String mergedSegment = "test" ; private Directory merge1Dir ; private Document doc1 = new Document ( ) ; private SegmentReader reader1 = null ; private Directory merge2Dir ; private Document doc2 = new Document ( ) ; private SegmentReader reader2 = null ; @ Override public void setUp ( ) throws Exception { } @ Override public void tearDown ( ) throws Exception { } public void test ( ) { } public void testMerge ( ) throws IOException { final Codec codec = Codec . getDefault ( ) ; final SegmentInfo si = new SegmentInfo ( mergedDir , Constants . LUCENE_MAIN_VERSION , mergedSegment , ( - 1 ) , false , codec , null , null ) ; <START_BUG> SegmentMerger merger = new SegmentMerger ( si , InfoStream . getDefault ( ) , mergedDir , IndexWriterConfig . DEFAULT_TERM_INDEX_INTERVAL , CheckAbort . NONE , null , new FieldInfos . FieldNumbers ( ) , newIOContext ( random ( ) ) ) ; <END_BUG> merger . add ( reader1 ) ; merger . add ( reader2 ) ; MergeState mergeState = merger . merge ( ) ; int docsMerged = mergeState . segmentInfo . getDocCount ( ) ; assertTrue ( ( docsMerged == 2 ) ) ; SegmentReader mergedReader = new SegmentReader ( new SegmentInfoPerCommit ( new SegmentInfo ( mergedDir , Constants . LUCENE_MAIN_VERSION , mergedSegment , docsMerged , false , codec , null , null ) , 0 , ( - 1L ) ) , DirectoryReader . DEFAULT_TERMS_INDEX_DIVISOR , newIOContext ( random ( ) ) ) ; assertTrue ( ( mergedReader != null ) ) ; assertTrue ( ( ( mergedReader . numDocs ( ) ) == 2 ) ) ; Document newDoc1 = mergedReader . document ( 0 ) ; assertTrue ( ( newDoc1 != null ) ) ; assertTrue ( ( ( DocHelper . numFields ( newDoc1 ) ) == ( ( DocHelper . numFields ( doc1 ) ) - ( unstored . size ( ) ) ) ) ) ; Document newDoc2 = mergedReader . document ( 1 ) ; assertTrue ( ( newDoc2 != null ) ) ; assertTrue ( ( ( DocHelper . numFields ( newDoc2 ) ) == ( ( DocHelper . numFields ( doc2 ) ) - ( unstored . size ( ) ) ) ) ) ; DocsEnum termDocs = _TestUtil . docs ( random ( ) , mergedReader , TEXT_FIELD_2_KEY , new BytesRef ( "field" ) , MultiFields . getLiveDocs ( mergedReader ) , null , 0 ) ; assertTrue ( ( termDocs != null ) ) ; assertTrue ( ( ( termDocs . nextDoc ( ) ) != ( DocIdSetIterator . NO_MORE_DOCS ) ) ) ; int tvCount = 0 ; for ( FieldInfo fieldInfo : mergedReader . getFieldInfos ( ) ) { if ( fieldInfo . hasVectors ( ) ) { tvCount ++ ; } } assertEquals ( "We<seq2seq4repair_space>do<seq2seq4repair_space>not<seq2seq4repair_space>have<seq2seq4repair_space>3<seq2seq4repair_space>fields<seq2seq4repair_space>that<seq2seq4repair_space>were<seq2seq4repair_space>indexed<seq2seq4repair_space>with<seq2seq4repair_space>term<seq2seq4repair_space>vector" , 3 , tvCount ) ; Terms vector = mergedReader . getTermVectors ( 0 ) . terms ( TEXT_FIELD_2_KEY ) ; assertNotNull ( vector ) ; assertEquals ( 3 , vector . size ( ) ) ; TermsEnum termsEnum = vector . iterator ( null ) ; int i = 0 ; while ( ( termsEnum . next ( ) ) != null ) { String term = termsEnum . term ( ) . utf8ToString ( ) ; int freq = ( ( int ) ( termsEnum . totalTermFreq ( ) ) ) ; assertTrue ( ( ( FIELD_2_TEXT . indexOf ( term ) ) != ( - 1 ) ) ) ; assertTrue ( ( ( DocHelper . FIELD_2_FREQS [ i ] ) == freq ) ) ; i ++ ; } TestSegmentReader . checkNorms ( mergedReader ) ; mergedReader . close ( ) ; } private static boolean equals ( MergeState . DocMap map1 , MergeState . DocMap map2 ) { } public void testBuildDocMap ( ) { } }

Fix:
SegmentMerger merger = new SegmentMerger ( si , InfoStream . getDefault ( ) , mergedDir , IndexWriterConfig . DEFAULT_TERM_INDEX_INTERVAL , CheckAbort . NONE , new FieldInfos . FieldNumbers ( ) , newIOContext ( random ( ) ) ) ;