Program: 168832
Project: 168832
Buggy source:
protected String[] appendSetOperands(StringBuilder sqlSb,SetOperationType setType,String operator,boolean isSubquery,List<String> operands,boolean hasOuterClause){
  boolean first=true;
  final boolean emulate=setType == SetOperationType.EXCEPT_ALL && !supportsExcept(true) || setType == SetOperationType.INTERSECT_ALL && !supportsIntersect(true);
  final String select="String_Node_Str";
  final String windowFunctionDummyOrderBy=getWindowFunctionDummyOrderBy();
  String[] aliases=null;
  if (needsAliasInSetOrderBy()) {
    int selectIndex=SqlUtils.indexOfSelect(operands.get(0));
    aliases=SqlUtils.getSelectItemAliases(operands.get(0),selectIndex);
  }
  for (  String operand : operands) {
    if (first) {
      first=false;
      if (emulate) {
        if (aliases == null) {
          int selectIndex=SqlUtils.indexOfSelect(operand);
          aliases=SqlUtils.getSelectItemAliases(operand,selectIndex);
        }
        sqlSb.append(select);
        for (int i=0; i < aliases.length; i++) {
          if (i != 0) {
            sqlSb.append("String_Node_Str");
          }
          sqlSb.append(aliases[i]);
        }
        sqlSb.append("String_Node_Str");
      }
    }
 else {
      sqlSb.append("String_Node_Str");
      sqlSb.append(operator);
      sqlSb.append("String_Node_Str");
    }
    if (emulate) {
      int selectIndex=SqlUtils.indexOfSelect(operand);
      String[] expressions=SqlUtils.getSelectItemExpressions(operand,selectIndex);
      sqlSb.append(select);
      sqlSb.append("String_Node_Str");
      for (int i=0; i < expressions.length; i++) {
        if (i != 0) {
          sqlSb.append("String_Node_Str");
        }
        sqlSb.append(expressions[i]);
      }
      if (windowFunctionDummyOrderBy != null) {
        sqlSb.append(windowFunctionDummyOrderBy);
      }
      sqlSb.append("String_Node_Str");
      sqlSb.append(operand,select.length(),operand.length());
    }
 else {
      boolean addWrapper=SqlUtils.indexOfOrderBy(operand) != -1;
      if (addWrapper) {
        sqlSb.append("String_Node_Str");
      }
      sqlSb.append(operand);
      if (addWrapper) {
        sqlSb.append(')');
      }
    }
  }
  if (emulate) {
    sqlSb.append(')');
  }
  return aliases;
}

Fixed version (ground truth):
protected String[] appendSetOperands(StringBuilder sqlSb,SetOperationType setType,String operator,boolean isSubquery,List<String> operands,boolean hasOuterClause){
  boolean first=true;
  final boolean emulate=setType == SetOperationType.EXCEPT_ALL && !supportsExcept(true) || setType == SetOperationType.INTERSECT_ALL && !supportsIntersect(true);
  final String select="String_Node_Str";
  final String windowFunctionDummyOrderBy=getWindowFunctionDummyOrderBy();
  String[] aliases=null;
  if (needsAliasInSetOrderBy()) {
    int selectIndex=SqlUtils.indexOfSelect(operands.get(0));
    aliases=SqlUtils.getSelectItemAliases(operands.get(0),selectIndex);
  }
  for (  String operand : operands) {
    boolean wasFirst=false;
    if (first) {
      first=false;
      wasFirst=true;
      if (emulate) {
        if (aliases == null) {
          int selectIndex=SqlUtils.indexOfSelect(operand);
          aliases=SqlUtils.getSelectItemAliases(operand,selectIndex);
        }
        sqlSb.append(select);
        for (int i=0; i < aliases.length; i++) {
          if (i != 0) {
            sqlSb.append("String_Node_Str");
          }
          sqlSb.append(aliases[i]);
        }
        sqlSb.append("String_Node_Str");
      }
    }
 else {
      sqlSb.append("String_Node_Str");
      sqlSb.append(operator);
      sqlSb.append("String_Node_Str");
    }
    if (emulate) {
      int selectIndex=SqlUtils.indexOfSelect(operand);
      String[] expressions=SqlUtils.getSelectItemExpressions(operand,selectIndex);
      sqlSb.append(select);
      sqlSb.append("String_Node_Str");
      for (int i=0; i < expressions.length; i++) {
        if (i != 0) {
          sqlSb.append("String_Node_Str");
        }
        sqlSb.append(expressions[i]);
      }
      if (windowFunctionDummyOrderBy != null) {
        sqlSb.append(windowFunctionDummyOrderBy);
      }
      sqlSb.append("String_Node_Str");
      sqlSb.append(operand,select.length(),operand.length());
    }
 else {
      boolean addWrapper=SqlUtils.indexOfOrderBy(operand) != -1;
      if (addWrapper) {
        sqlSb.append("String_Node_Str");
      }
      if ((addWrapper || wasFirst) && operand.charAt(0) == '(') {
        sqlSb.append(operand,1,operand.length() - 1);
      }
 else {
        sqlSb.append(operand);
      }
      if (addWrapper) {
        sqlSb.append(')');
      }
    }
  }
  if (emulate) {
    sqlSb.append(')');
  }
  return aliases;
}