Program: 65325
Project: 65325
Buggy source:
/** 
 * INTERNAL: Extract the nested attribute expressions that apply to this mapping. This is used for partial objects and joining.
 * @param rootExpressionsAllowed true if newRoot itself can be one of theexpressions returned
 */
protected List<Expression> extractNestedExpressions(List<Expression> expressions,ExpressionBuilder newRoot,boolean rootExpressionsAllowed){
  List<Expression> nestedExpressions=new ArrayList(expressions.size());
  for (  Expression next : expressions) {
    if (!next.isQueryKeyExpression()) {
      continue;
    }
    QueryKeyExpression expression=(QueryKeyExpression)next;
    ObjectExpression base=expression;
    boolean afterBase=false;
    boolean done=false;
    ObjectExpression prevExpression=base;
    while (!base.getBaseExpression().isExpressionBuilder() && !done) {
      base=(ObjectExpression)base.getBaseExpression();
      while (!base.isExpressionBuilder() && base.getMapping().isAggregateObjectMapping()) {
        base=(ObjectExpression)base.getBaseExpression();
      }
      if (base.isExpressionBuilder()) {
        done=true;
        base=prevExpression;
      }
 else {
        prevExpression=base;
        afterBase=true;
      }
    }
    if (afterBase && base.getName().equals(getAttributeName())) {
      nestedExpressions.add(expression.rebuildOn(base,newRoot));
    }
 else     if (rootExpressionsAllowed && expression.getBaseExpression().isExpressionBuilder() && expression.getName().equals(getAttributeName())) {
      nestedExpressions.add(newRoot);
    }
  }
  return nestedExpressions;
}

Fixed version (ground truth):
/** 
 * INTERNAL: Extract the nested attribute expressions that apply to this mapping. This is used for partial objects and joining.
 * @param rootExpressionsAllowed true if newRoot itself can be one of theexpressions returned
 */
protected List<Expression> extractNestedExpressions(List<Expression> expressions,ExpressionBuilder newRoot,boolean rootExpressionsAllowed){
  List<Expression> nestedExpressions=new ArrayList(expressions.size());
  for (  Expression next : expressions) {
    if (!next.isQueryKeyExpression()) {
      continue;
    }
    QueryKeyExpression expression=(QueryKeyExpression)next;
    ObjectExpression base=expression;
    boolean afterBase=false;
    boolean done=false;
    ObjectExpression prevExpression=base;
    while (!base.getBaseExpression().isExpressionBuilder() && !done) {
      base=(ObjectExpression)base.getBaseExpression();
      while (!base.isExpressionBuilder() && (base.getMapping() != null && base.getMapping().isAggregateObjectMapping())) {
        base=(ObjectExpression)base.getBaseExpression();
      }
      if (base.isExpressionBuilder()) {
        done=true;
        base=prevExpression;
      }
 else {
        prevExpression=base;
        afterBase=true;
      }
    }
    if (afterBase && base.getName().equals(getAttributeName())) {
      nestedExpressions.add(expression.rebuildOn(base,newRoot));
    }
 else     if (rootExpressionsAllowed && expression.getBaseExpression().isExpressionBuilder() && expression.getName().equals(getAttributeName())) {
      nestedExpressions.add(newRoot);
    }
  }
  return nestedExpressions;
}