Buggy code:
@ Slow public class TestJoinUtil extends LuceneTestCase { public void testSimple ( ) throws Exception { } public void testSimpleWithScoring ( ) throws Exception { } @ Test public void testSingleValueRandomJoin ( ) throws Exception { } @ Test public void testMultiValueRandomJoin ( ) throws Exception { } private void executeRandomJoin ( boolean multipleValuesPerDocument , int maxIndexIter , int maxSearchIter , int numberOfDocumentsToIndex ) throws Exception { } private TestJoinUtil . IndexIterationContext createContext ( int nDocs , RandomIndexWriter writer , boolean multipleValuesPerDocument ) throws IOException { } private TestJoinUtil . IndexIterationContext createContext ( int nDocs , RandomIndexWriter fromWriter , RandomIndexWriter toWriter , boolean multipleValuesPerDocument ) throws IOException { } private TopDocs createExpectedTopDocs ( String queryValue , final boolean from , final ScoreMode scoreMode , TestJoinUtil . IndexIterationContext context ) { } private FixedBitSet createExpectedResult ( String queryValue , boolean from , IndexReader topLevelReader , TestJoinUtil . IndexIterationContext context ) throws IOException { final Map < String , List < TestJoinUtil . RandomDoc > > randomValueDocs ; final Map < String , List < TestJoinUtil . RandomDoc > > linkValueDocuments ; if ( from ) { randomValueDocs = context . randomValueFromDocs ; linkValueDocuments = context . toDocuments ; } else { randomValueDocs = context . randomValueToDocs ; linkValueDocuments = context . fromDocuments ; } FixedBitSet expectedResult = new FixedBitSet ( topLevelReader . maxDoc ( ) ) ; List < TestJoinUtil . RandomDoc > matchingDocs = randomValueDocs . get ( queryValue ) ; if ( matchingDocs == null ) { return new FixedBitSet ( topLevelReader . maxDoc ( ) ) ; } for ( TestJoinUtil . RandomDoc matchingDoc : matchingDocs ) { for ( String linkValue : matchingDoc . linkValues ) { List < TestJoinUtil . RandomDoc > otherMatchingDocs = linkValueDocuments . get ( linkValue ) ; if ( otherMatchingDocs == null ) { continue ; } for ( TestJoinUtil . RandomDoc otherSideDoc : otherMatchingDocs ) { <START_BUG> DocsEnum docsEnum = MultiFields . getTermDocsEnum ( topLevelReader , MultiFields . getLiveDocs ( topLevelReader ) , "id" , new BytesRef ( otherSideDoc . id ) , 0 ) ; <END_BUG> assert docsEnum != null ; int doc = docsEnum . nextDoc ( ) ; expectedResult . set ( doc ) ; } } } return expectedResult ; } private static class IndexIterationContext { String [ ] randomUniqueValues ; boolean [ ] randomFrom ; Map < String , List < TestJoinUtil . RandomDoc > > fromDocuments = new HashMap < String , List < TestJoinUtil . RandomDoc > > ( ) ; Map < String , List < TestJoinUtil . RandomDoc > > toDocuments = new HashMap < String , List < TestJoinUtil . RandomDoc > > ( ) ; Map < String , List < TestJoinUtil . RandomDoc > > randomValueFromDocs = new HashMap < String , List < TestJoinUtil . RandomDoc > > ( ) ; Map < String , List < TestJoinUtil . RandomDoc > > randomValueToDocs = new HashMap < String , List < TestJoinUtil . RandomDoc > > ( ) ; Map < String , Map < Integer , TestJoinUtil . JoinScore > > fromHitsToJoinScore = new HashMap < String , Map < Integer , TestJoinUtil . JoinScore > > ( ) ; Map < String , Map < Integer , TestJoinUtil . JoinScore > > toHitsToJoinScore = new HashMap < String , Map < Integer , TestJoinUtil . JoinScore > > ( ) ; } private static class RandomDoc { final String id ; final List < String > linkValues ; final String value ; final boolean from ; private RandomDoc ( String id , int numberOfLinkValues , String value , boolean from ) { } } private static class JoinScore { float maxScore ; float total ; int count ; void addScore ( float score ) { } float score ( ScoreMode mode ) { } } }

Fix:
DocsEnum docsEnum = MultiFields . getTermDocsEnum ( topLevelReader , MultiFields . getLiveDocs ( topLevelReader ) , "id" , new BytesRef ( otherSideDoc . id ) , false ) ;