Buggy code:
public class ToParentBlockJoinQuery extends Query { private final Filter parentsFilter ; private final Query childQuery ; private final Query origChildQuery ; private final ScoreMode scoreMode ; public ToParentBlockJoinQuery ( Query childQuery , Filter parentsFilter , ScoreMode scoreMode ) { } private ToParentBlockJoinQuery ( Query origChildQuery , Query childQuery , Filter parentsFilter , ScoreMode scoreMode ) { } @ Override public Weight createWeight ( IndexSearcher searcher ) throws IOException { } private static class BlockJoinWeight extends Weight { private final Query joinQuery ; private final Weight childWeight ; private final Filter parentsFilter ; private final ScoreMode scoreMode ; public BlockJoinWeight ( Query joinQuery , Weight childWeight , Filter parentsFilter , ScoreMode scoreMode ) { } @ Override public Query getQuery ( ) { } @ Override public float getValueForNormalization ( ) throws IOException { } @ Override public void normalize ( float norm , float topLevelBoost ) { } @ Override public Scorer scorer ( AtomicReaderContext readerContext , boolean scoreDocsInOrder , boolean topScorer , Bits acceptDocs ) throws IOException { } @ Override public Explanation explain ( AtomicReaderContext context , int doc ) throws IOException { } @ Override public boolean scoresDocsOutOfOrder ( ) { } } static class BlockJoinScorer extends Scorer { private final Scorer childScorer ; private final FixedBitSet parentBits ; private final ScoreMode scoreMode ; private final Bits acceptDocs ; private int parentDoc = - 1 ; private int prevParentDoc ; private float parentScore ; private int parentFreq ; private int nextChildDoc ; private int [ ] pendingChildDocs ; private float [ ] pendingChildScores ; private int childDocUpto ; public BlockJoinScorer ( Weight weight , Scorer childScorer , FixedBitSet parentBits , int firstChildDoc , ScoreMode scoreMode , Bits acceptDocs ) { } @ Override public Collection < ChildScorer > getChildren ( ) { } int getChildCount ( ) { } int getParentDoc ( ) { } int [ ] swapChildDocs ( int [ ] other ) { } float [ ] swapChildScores ( float [ ] other ) { } @ Override public int nextDoc ( ) throws IOException { } @ Override public int docID ( ) { } @ Override public float score ( ) throws IOException { } @ Override public int freq ( ) { } @ Override public int advance ( int parentTarget ) throws IOException { } public Explanation explain ( int docBase ) throws IOException { } @ Override public long cost ( ) { } public void trackPendingChildHits ( ) { } } @ Override public void extractTerms ( Set < Term > terms ) { } @ Override public Query rewrite ( IndexReader reader ) throws IOException { final Query childRewrite = childQuery . rewrite ( reader ) ; if ( childRewrite != ( childQuery ) ) { <START_BUG> Query rewritten = new ToParentBlockJoinQuery ( childQuery , childRewrite , parentsFilter , scoreMode ) ; <END_BUG> rewritten . setBoost ( getBoost ( ) ) ; return rewritten ; } else { return this ; } } @ Override public String toString ( String field ) { } @ Override public boolean equals ( Object _other ) { } @ Override public int hashCode ( ) { } }

Fix:
Query rewritten = new ToParentBlockJoinQuery ( origChildQuery , childRewrite , parentsFilter , scoreMode ) ;