Buggy code:
public TopDocs searchAfter ( ScoreDoc after , Query query , Filter filter , int n , Sort sort ) throws IOException { } public TopFieldDocs search ( Query query , int n , Sort sort ) throws IOException { } public TopDocs searchAfter ( ScoreDoc after , Query query , int n , Sort sort ) throws IOException { } public TopDocs searchAfter ( ScoreDoc after , Query query , Filter filter , int n , Sort sort , boolean doDocScores , boolean doMaxScore ) throws IOException { } protected TopDocs search ( Weight weight , ScoreDoc after , int nDocs ) throws IOException { } protected TopDocs search ( List < AtomicReaderContext > leaves , Weight weight , ScoreDoc after , int nDocs ) throws IOException { } protected TopFieldDocs search ( Weight weight , final int nDocs , Sort sort , boolean doDocScores , boolean doMaxScore ) throws IOException { } protected TopFieldDocs search ( Weight weight , FieldDoc after , int nDocs , Sort sort , boolean fillFields , boolean doDocScores , boolean doMaxScore ) throws IOException { } protected TopFieldDocs search ( List < AtomicReaderContext > leaves , Weight weight , FieldDoc after , int nDocs , Sort sort , boolean fillFields , boolean doDocScores , boolean doMaxScore ) throws IOException { } protected void search ( List < AtomicReaderContext > leaves , Weight weight , Collector collector ) throws IOException { } public Query rewrite ( Query original ) throws IOException { } public Explanation explain ( Query query , int doc ) throws IOException { } protected Explanation explain ( Weight weight , int doc ) throws IOException { } public Weight createNormalizedWeight ( Query query ) throws IOException { } public IndexReaderContext getTopReaderContext ( ) { } private static final class SearcherCallableNoSort implements Callable < TopDocs > { private final Lock lock ; private final IndexSearcher searcher ; private final Weight weight ; private final ScoreDoc after ; private final int nDocs ; private final HitQueue hq ; private final IndexSearcher . LeafSlice slice ; public SearcherCallableNoSort ( Lock lock , IndexSearcher searcher , IndexSearcher . LeafSlice slice , Weight weight , ScoreDoc after , int nDocs , HitQueue hq ) { } @ Override public TopDocs call ( ) throws IOException { final TopDocs docs = searcher . search ( Arrays . asList ( slice . leaves ) , weight , after , nDocs ) ; final ScoreDoc [ ] scoreDocs = docs . scoreDocs ; lock . lock ( ) ; try { for ( int j = 0 ; j < ( scoreDocs . length ) ; j ++ ) { final ScoreDoc scoreDoc = scoreDocs [ j ] ; if ( scoreDoc == ( hq . insertWithOverflow ( scoreDoc ) ) ) { break ; } } } finally { lock . unlock ( ) ; } return docs ; } } private static final class SearcherCallableWithSort implements Callable < TopFieldDocs > { private final Lock lock ; private final IndexSearcher searcher ; private final Weight weight ; private final int nDocs ; private final TopFieldCollector hq ; private final Sort sort ; private final IndexSearcher . LeafSlice slice ; private final FieldDoc after ; private final boolean doDocScores ; private final boolean doMaxScore ; public SearcherCallableWithSort ( Lock lock , IndexSearcher searcher , IndexSearcher . LeafSlice slice , Weight weight , FieldDoc after , int nDocs , TopFieldCollector hq , Sort sort , boolean doDocScores , boolean doMaxScore ) { } private final class FakeScorer extends Scorer { float score ; int doc ; public FakeScorer ( ) { } @ Override public int advance ( int target ) { } @ Override public int docID ( ) { } @ Override public int freq ( ) { } @ Override public int nextDoc ( ) { } @ Override public float score ( ) { } @ Override public long cost ( ) { } } private final IndexSearcher . SearcherCallableWithSort . FakeScorer fakeScorer = new IndexSearcher . SearcherCallableWithSort . FakeScorer ( ) ; @ Override public TopFieldDocs call ( ) throws IOException { assert ( slice . leaves . length ) == 1 ; <START_BUG> final TopFieldDocs docs = searcher . search ( Arrays . asList ( slice . leaves ) , weight , after , nDocs , sort , true , doDocScores , doMaxScore ) ; <END_BUG> lock . lock ( ) ; try { final AtomicReaderContext ctx = slice . leaves [ 0 ] ; final int base = ctx . docBase ; hq . setNextReader ( ctx ) ; hq . setScorer ( fakeScorer ) ; for ( ScoreDoc scoreDoc : docs . scoreDocs ) { fakeScorer . doc = ( scoreDoc . doc ) - base ; fakeScorer . score = scoreDoc . score ; hq . collect ( ( ( scoreDoc . doc ) - base ) ) ; } if ( ( doMaxScore ) && ( ( docs . getMaxScore ( ) ) > ( hq . maxScore ) ) ) { hq . maxScore = docs . getMaxScore ( ) ; } } finally { lock . unlock ( ) ; } return docs ; } } private static final class ExecutionHelper < T > implements Iterable < T > , Iterator < T > { private final CompletionService < T > service ; private int numTasks ; ExecutionHelper ( final Executor executor ) { } @ Override public boolean hasNext ( ) { } public void submit ( Callable < T > task ) { } @ Override public T next ( ) { } @ Override public void remove ( ) { } @ Override public Iterator < T > iterator ( ) { } } public static class LeafSlice { final AtomicReaderContext [ ] leaves ; public LeafSlice ( AtomicReaderContext ... leaves ) { } } @ Override public String toString ( ) { }

Fix:
final TopFieldDocs docs = searcher . search ( Arrays . asList ( slice . leaves ) , weight , after , nDocs , sort , true , ( ( doDocScores ) || ( sort . needsScores ( ) ) ) , doMaxScore ) ;