Program: 168805
Project: 168805
Buggy source:
protected Expression asExpression(AbstractCommonQueryBuilder<?,?,?,?,?> queryBuilder){
  if (queryBuilder instanceof BaseFinalSetOperationBuilderImpl<?,?,?>) {
    BaseFinalSetOperationBuilderImpl<?,?,?> operationBuilder=(BaseFinalSetOperationBuilderImpl<?,?,?>)queryBuilder;
    SetOperationManager operationManager=operationBuilder.setOperationManager;
    if (operationManager.getOperator() == null || !operationManager.hasSetOperations()) {
      return asExpression(operationManager.getStartQueryBuilder());
    }
    List<Expression> setOperationArgs=new ArrayList<Expression>(operationManager.getSetOperations().size() + 2);
    StringBuilder nameSb=new StringBuilder();
    nameSb.append("String_Node_Str");
    nameSb.append(operationManager.getOperator().name());
    setOperationArgs.add(new StringLiteral(nameSb.toString()));
    setOperationArgs.add(asExpression(operationManager.getStartQueryBuilder()));
    List<AbstractCommonQueryBuilder<?,?,?,?,?>> setOperands=operationManager.getSetOperations();
    int operandsSize=setOperands.size();
    for (int i=0; i < operandsSize; i++) {
      setOperationArgs.add(asExpression(setOperands.get(i)));
    }
    List<? extends OrderByElement> orderByElements=operationBuilder.getOrderByElements();
    if (orderByElements.size() > 0) {
      setOperationArgs.add(new StringLiteral("String_Node_Str"));
      int orderByElementsSize=orderByElements.size();
      for (int i=0; i < orderByElementsSize; i++) {
        StringBuilder argSb=new StringBuilder(20);
        argSb.append(orderByElements.get(i).toString());
        setOperationArgs.add(new StringLiteral(argSb.toString()));
      }
    }
    if (operationBuilder.hasLimit()) {
      if (operationBuilder.maxResults != Integer.MAX_VALUE) {
        setOperationArgs.add(new StringLiteral("String_Node_Str"));
        setOperationArgs.add(new NumericLiteral(Integer.toString(operationBuilder.maxResults),NumericType.INTEGER));
      }
      if (operationBuilder.firstResult != 0) {
        setOperationArgs.add(new StringLiteral("String_Node_Str"));
        setOperationArgs.add(new NumericLiteral(Integer.toString(operationBuilder.firstResult),NumericType.INTEGER));
      }
    }
    Expression functionExpr=new FunctionExpression("String_Node_Str",setOperationArgs);
    return functionExpr;
  }
  String queryString=queryBuilder.getQueryString();
  final StringBuilder subquerySb=new StringBuilder(queryString.length() + 2);
  subquerySb.append(queryString);
  return new SubqueryExpression(new Subquery(){
    @Override public String getQueryString(){
      return subquerySb.toString();
    }
  }
);
}

Fixed version (ground truth):
protected Expression asExpression(AbstractCommonQueryBuilder<?,?,?,?,?> queryBuilder){
  if (queryBuilder instanceof BaseFinalSetOperationBuilderImpl<?,?,?>) {
    BaseFinalSetOperationBuilderImpl<?,?,?> operationBuilder=(BaseFinalSetOperationBuilderImpl<?,?,?>)queryBuilder;
    SetOperationManager operationManager=operationBuilder.setOperationManager;
    if (operationManager.getOperator() == null || !operationManager.hasSetOperations()) {
      return asExpression(operationManager.getStartQueryBuilder());
    }
    List<Expression> setOperationArgs=new ArrayList<Expression>(operationManager.getSetOperations().size() + 2);
    StringBuilder nameSb=new StringBuilder();
    nameSb.append("String_Node_Str");
    nameSb.append(operationManager.getOperator().name());
    setOperationArgs.add(new StringLiteral(nameSb.toString()));
    setOperationArgs.add(asExpression(operationManager.getStartQueryBuilder()));
    List<AbstractCommonQueryBuilder<?,?,?,?,?>> setOperands=operationManager.getSetOperations();
    int operandsSize=setOperands.size();
    for (int i=0; i < operandsSize; i++) {
      setOperationArgs.add(asExpression(setOperands.get(i)));
    }
    List<? extends OrderByElement> orderByElements=operationBuilder.getOrderByElements();
    if (orderByElements.size() > 0) {
      setOperationArgs.add(new StringLiteral("String_Node_Str"));
      int orderByElementsSize=orderByElements.size();
      for (int i=0; i < orderByElementsSize; i++) {
        StringBuilder argSb=new StringBuilder(20);
        argSb.append(orderByElements.get(i).toString());
        setOperationArgs.add(new StringLiteral(argSb.toString()));
      }
    }
    if (operationBuilder.hasLimit()) {
      if (operationBuilder.maxResults != Integer.MAX_VALUE) {
        setOperationArgs.add(new StringLiteral("String_Node_Str"));
        setOperationArgs.add(new NumericLiteral(Integer.toString(operationBuilder.maxResults),NumericType.INTEGER));
      }
      if (operationBuilder.firstResult != 0) {
        setOperationArgs.add(new StringLiteral("String_Node_Str"));
        setOperationArgs.add(new NumericLiteral(Integer.toString(operationBuilder.firstResult),NumericType.INTEGER));
      }
    }
    Expression functionExpr=new FunctionExpression("String_Node_Str",setOperationArgs);
    return functionExpr;
  }
  String queryString=queryBuilder.getQueryString();
  final StringBuilder subquerySb=new StringBuilder(queryString.length() + 2);
  subquerySb.append(queryString);
  Expression expression=new SubqueryExpression(new Subquery(){
    @Override public String getQueryString(){
      return subquerySb.toString();
    }
  }
);
  if (queryBuilder.hasLimit()) {
    final boolean hasFirstResult=queryBuilder.getFirstResult() != 0;
    final boolean hasMaxResults=queryBuilder.getMaxResults() != Integer.MAX_VALUE;
    List<Expression> arguments=new ArrayList<Expression>(2);
    arguments.add(new StringLiteral("String_Node_Str"));
    arguments.add(expression);
    if (!hasMaxResults) {
      throw new IllegalArgumentException("String_Node_Str");
    }
 else {
      arguments.add(new NumericLiteral(Integer.toString(queryBuilder.getMaxResults()),NumericType.INTEGER));
    }
    if (hasFirstResult) {
      arguments.add(new NumericLiteral(Integer.toString(queryBuilder.getFirstResult()),NumericType.INTEGER));
    }
    expression=new FunctionExpression("String_Node_Str",arguments);
  }
  return expression;
}