Buggy code:
public class PrelUtil { public static final String HASH_EXPR_NAME = "E_X_P_R_H_A_S_H_F_I_E_L_D" ; public static List < Ordering > getOrdering ( RelCollation collation , RelDataType rowType ) { List < Ordering > orderExpr = Lists . newArrayList ( ) ; final List < String > childFields = rowType . getFieldNames ( ) ; for ( RelFieldCollation fc : collation . getFieldCollations ( ) ) { <START_BUG> FieldReference fr = new FieldReference ( childFields . get ( fc . getFieldIndex ( ) ) , ExpressionPosition . UNKNOWN ) ; <END_BUG> orderExpr . add ( new Ordering ( fc . getDirection ( ) , fr , fc . nullDirection ) ) ; } return orderExpr ; } public static LogicalExpression getHashExpression ( List < DistributionField > fields , RelDataType rowType ) { } public static Iterator < Prel > iter ( RelNode ... nodes ) { } public static Iterator < Prel > iter ( List < RelNode > nodes ) { } public static PlannerSettings getSettings ( RelOptCluster cluster ) { } public static PlannerSettings getPlannerSettings ( RelOptPlanner planner ) { } public static Prel removeSvIfRequired ( Prel prel , SelectionVectorMode ... allowed ) { } public static int getLastUsedColumnReference ( List < RexNode > projects ) { } public static PrelUtil . ProjectPushInfo getColumns ( RelDataType rowType , List < RexNode > projects ) { } public static class DesiredField { public final int origIndex ; public final String name ; public final RelDataTypeField field ; public DesiredField ( int origIndex , String name , RelDataTypeField field ) { } @ Override public int hashCode ( ) { } @ Override public boolean equals ( Object obj ) { } } public static class ProjectPushInfo { public final List < SchemaPath > columns ; public final List < PrelUtil . DesiredField > desiredFields ; public final PrelUtil . InputRewriter rewriter ; private final List < String > fieldNames ; private final List < RelDataType > types ; public ProjectPushInfo ( List < SchemaPath > columns , ImmutableList < PrelUtil . DesiredField > desiredFields ) { } public PrelUtil . InputRewriter getInputRewriter ( ) { } public boolean isStarQuery ( ) { } public RelDataType createNewRowType ( RelDataTypeFactory factory ) { } } private static class LastUsedRefVisitor extends RexVisitorImpl { int lastUsedRef = - 1 ; protected LastUsedRefVisitor ( ) { } @ Override public Void visitInputRef ( RexInputRef inputRef ) { } @ Override public Void visitCall ( RexCall call ) { } public int getLastUsedReference ( ) { } } private static class RefFieldsVisitor extends RexVisitorImpl < PathSegment > { final Set < SchemaPath > columns = Sets . newLinkedHashSet ( ) ; private final List < String > fieldNames ; private final List < RelDataTypeField > fields ; private final Set < PrelUtil . DesiredField > desiredFields = Sets . newHashSet ( ) ; public RefFieldsVisitor ( RelDataType rowType ) { } public void addColumn ( PathSegment segment ) { } public PrelUtil . ProjectPushInfo getInfo ( ) { } @ Override public PathSegment visitInputRef ( RexInputRef inputRef ) { } @ Override public PathSegment visitCall ( RexCall call ) { } private PathSegment convertLiteral ( RexLiteral literal ) { } } public static RelTraitSet fixTraits ( RelOptRuleCall call , RelTraitSet set ) { } public static RelTraitSet fixTraits ( RelOptPlanner cluster , RelTraitSet set ) { } public static class InputRefRemap { private int oldIndex ; private int newIndex ; public InputRefRemap ( int oldIndex , int newIndex ) { } public int getOldIndex ( ) { } public int getNewIndex ( ) { } } public static class InputRewriter extends RexShuttle { final IntIntOpenHashMap map ; public InputRewriter ( IntIntOpenHashMap map ) { } @ Override public RexNode visitInputRef ( RexInputRef inputRef ) { } @ Override public RexNode visitLocalRef ( RexLocalRef localRef ) { } } }

Fix:
FieldReference fr = new FieldReference ( childFields . get ( fc . getFieldIndex ( ) ) , ExpressionPosition . UNKNOWN , false ) ;