Program: 30722
Project: 30722
Buggy source:
private void toSink0(CharSink sink,boolean joinSlave){
  if (columns.size() > 0) {
    sink.put(getSelectModelTypeText()).put(' ');
    for (int i=0, n=columns.size(); i < n; i++) {
      if (i > 0) {
        sink.put("String_Node_Str");
      }
      QueryColumn column=columns.getQuick(i);
      String name=column.getName();
      String alias=column.getAlias();
      ExprNode ast=column.getAst();
      if (column instanceof AnalyticColumn || name == null) {
        ast.toSink(sink);
        if (alias != null) {
          aliasToSink(alias,sink);
        }
        if (name != null) {
          AnalyticColumn ac=(AnalyticColumn)column;
          sink.put("String_Node_Str");
          final ObjList<ExprNode> partitionBy=ac.getPartitionBy();
          if (partitionBy.size() > 0) {
            sink.put("String_Node_Str");
            for (int k=0, z=partitionBy.size(); k < z; k++) {
              if (k > 0) {
                sink.put("String_Node_Str");
              }
              partitionBy.getQuick(k).toSink(sink);
            }
          }
          final ObjList<ExprNode> orderBy=ac.getOrderBy();
          if (orderBy.size() > 0) {
            if (partitionBy.size() > 0) {
              sink.put(' ');
            }
            sink.put("String_Node_Str");
            for (int k=0, z=orderBy.size(); k < z; k++) {
              if (k > 0) {
                sink.put("String_Node_Str");
              }
              orderBy.getQuick(k).toSink(sink);
              if (ac.getOrderByDirection().getQuick(k) == 1) {
                sink.put("String_Node_Str");
              }
            }
          }
          sink.put(')');
        }
      }
 else {
        ast.toSink(sink);
        if (alias != null && (ast.type != ExprNode.LITERAL || !ast.token.equals(alias))) {
          aliasToSink(alias,sink);
        }
      }
    }
    sink.put("String_Node_Str");
  }
  if (tableName != null) {
    sink.put(tableName.token);
    if (alias != null) {
      aliasToSink(alias.token,sink);
    }
  }
 else {
    sink.put('(');
    nestedModel.toSink(sink);
    sink.put(')');
    if (alias != null) {
      aliasToSink(alias.token,sink);
    }
  }
  if (timestamp != null) {
    sink.put("String_Node_Str");
    timestamp.toSink(sink);
    sink.put(')');
  }
  if (latestBy != null) {
    sink.put("String_Node_Str");
    latestBy.toSink(sink);
  }
  if (orderedJoinModels.size() > 1) {
    for (int i=0, n=orderedJoinModels.size(); i < n; i++) {
      QueryModel model=joinModels.getQuick(orderedJoinModels.getQuick(i));
      if (model != this) {
switch (model.getJoinType()) {
case JOIN_OUTER:
          sink.put("String_Node_Str");
        break;
case JOIN_ASOF:
      sink.put("String_Node_Str");
    break;
case JOIN_CROSS:
  sink.put("String_Node_Str");
break;
default :
sink.put("String_Node_Str");
}
if (model.getWhereClause() != null) {
sink.put('(');
model.toSink0(sink,true);
sink.put(')');
if (model.getAlias() != null) {
aliasToSink(model.getAlias().token,sink);
}
}
 else {
model.toSink0(sink,true);
}
JoinContext jc=model.getContext();
if (jc != null && jc.aIndexes.size() > 0) {
sink.put("String_Node_Str");
for (int k=0, z=jc.aIndexes.size(); k < z; k++) {
if (k > 0) {
sink.put("String_Node_Str");
}
jc.aNodes.getQuick(k).toSink(sink);
sink.put("String_Node_Str");
jc.bNodes.getQuick(k).toSink(sink);
}
}
if (model.getPostJoinWhereClause() != null) {
sink.put("String_Node_Str");
model.getPostJoinWhereClause().toSink(sink);
}
}
}
}
if (whereClause != null) {
sink.put("String_Node_Str");
whereClause.toSink(sink);
}
if (constWhereClause != null) {
sink.put("String_Node_Str");
constWhereClause.toSink(sink);
}
if (!joinSlave && postJoinWhereClause != null) {
sink.put("String_Node_Str");
postJoinWhereClause.toSink(sink);
}
if (sampleBy != null) {
sink.put("String_Node_Str");
sampleBy.toSink(sink);
}
if (orderBy.size() > 0) {
sink.put("String_Node_Str");
for (int i=0, n=orderBy.size(); i < n; i++) {
if (i > 0) {
sink.put("String_Node_Str");
}
orderBy.getQuick(i).toSink(sink);
if (orderByDirection.getQuick(i) == 1) {
sink.put("String_Node_Str");
}
}
}
if (limitLo != null || limitHi != null) {
sink.put("String_Node_Str");
if (limitLo != null) {
limitLo.toSink(sink);
}
if (limitHi != null) {
sink.put(',');
limitHi.toSink(sink);
}
}
}

Fixed version (ground truth):
private void toSink0(CharSink sink,boolean joinSlave){
  if (columns.size() > 0) {
    sink.put(getSelectModelTypeText()).put(' ');
    for (int i=0, n=columns.size(); i < n; i++) {
      if (i > 0) {
        sink.put("String_Node_Str");
      }
      QueryColumn column=columns.getQuick(i);
      String name=column.getName();
      String alias=column.getAlias();
      ExprNode ast=column.getAst();
      if (column instanceof AnalyticColumn || name == null) {
        ast.toSink(sink);
        if (alias != null) {
          aliasToSink(alias,sink);
        }
        if (name != null) {
          AnalyticColumn ac=(AnalyticColumn)column;
          sink.put("String_Node_Str");
          final ObjList<ExprNode> partitionBy=ac.getPartitionBy();
          if (partitionBy.size() > 0) {
            sink.put("String_Node_Str");
            for (int k=0, z=partitionBy.size(); k < z; k++) {
              if (k > 0) {
                sink.put("String_Node_Str");
              }
              partitionBy.getQuick(k).toSink(sink);
            }
          }
          final ObjList<ExprNode> orderBy=ac.getOrderBy();
          if (orderBy.size() > 0) {
            if (partitionBy.size() > 0) {
              sink.put(' ');
            }
            sink.put("String_Node_Str");
            for (int k=0, z=orderBy.size(); k < z; k++) {
              if (k > 0) {
                sink.put("String_Node_Str");
              }
              orderBy.getQuick(k).toSink(sink);
              if (ac.getOrderByDirection().getQuick(k) == 1) {
                sink.put("String_Node_Str");
              }
            }
          }
          sink.put(')');
        }
      }
 else {
        ast.toSink(sink);
        if (alias != null && (ast.type != ExprNode.LITERAL || !ast.token.equals(alias))) {
          aliasToSink(alias,sink);
        }
      }
    }
    sink.put("String_Node_Str");
  }
  if (tableName != null) {
    sink.put(tableName.token);
    if (alias != null) {
      aliasToSink(alias.token,sink);
    }
  }
 else {
    sink.put('(');
    nestedModel.toSink(sink);
    sink.put(')');
    if (alias != null) {
      aliasToSink(alias.token,sink);
    }
  }
  if (timestamp != null) {
    sink.put("String_Node_Str");
    timestamp.toSink(sink);
    sink.put(')');
  }
  if (getLatestBy() != null) {
    sink.put("String_Node_Str");
    getLatestBy().toSink(sink);
  }
  if (orderedJoinModels.size() > 1) {
    for (int i=0, n=orderedJoinModels.size(); i < n; i++) {
      QueryModel model=joinModels.getQuick(orderedJoinModels.getQuick(i));
      if (model != this) {
switch (model.getJoinType()) {
case JOIN_OUTER:
          sink.put("String_Node_Str");
        break;
case JOIN_ASOF:
      sink.put("String_Node_Str");
    break;
case JOIN_CROSS:
  sink.put("String_Node_Str");
break;
default :
sink.put("String_Node_Str");
}
if (model.getWhereClause() != null) {
sink.put('(');
model.toSink0(sink,true);
sink.put(')');
if (model.getAlias() != null) {
aliasToSink(model.getAlias().token,sink);
}
 else if (model.getTableName() != null) {
aliasToSink(model.getTableName().token,sink);
}
}
 else {
model.toSink0(sink,true);
}
JoinContext jc=model.getContext();
if (jc != null && jc.aIndexes.size() > 0) {
sink.put("String_Node_Str");
for (int k=0, z=jc.aIndexes.size(); k < z; k++) {
if (k > 0) {
sink.put("String_Node_Str");
}
jc.aNodes.getQuick(k).toSink(sink);
sink.put("String_Node_Str");
jc.bNodes.getQuick(k).toSink(sink);
}
}
if (model.getPostJoinWhereClause() != null) {
sink.put("String_Node_Str");
model.getPostJoinWhereClause().toSink(sink);
}
}
}
}
if (whereClause != null) {
sink.put("String_Node_Str");
whereClause.toSink(sink);
}
if (constWhereClause != null) {
sink.put("String_Node_Str");
constWhereClause.toSink(sink);
}
if (!joinSlave && postJoinWhereClause != null) {
sink.put("String_Node_Str");
postJoinWhereClause.toSink(sink);
}
if (sampleBy != null) {
sink.put("String_Node_Str");
sampleBy.toSink(sink);
}
if (orderBy.size() > 0) {
sink.put("String_Node_Str");
for (int i=0, n=orderBy.size(); i < n; i++) {
if (i > 0) {
sink.put("String_Node_Str");
}
orderBy.getQuick(i).toSink(sink);
if (orderByDirection.getQuick(i) == 1) {
sink.put("String_Node_Str");
}
}
}
if (getLimitLo() != null || getLimitHi() != null) {
sink.put("String_Node_Str");
if (getLimitLo() != null) {
getLimitLo().toSink(sink);
}
if (getLimitHi() != null) {
sink.put(',');
getLimitHi().toSink(sink);
}
}
}