Program: 51530
Project: 51530
Buggy source:
/** 
 * Generates the SQL to find all root members of a parent-child hierarchy. For example, <blockquote> <pre>SELECT "employee_id" FROM "employee" WHERE "supervisor_id" IS NULL GROUP BY "employee_id"</pre> </blockquote> retrieves the root members of the <code>[Employee]</code> hierarchy. <p>Currently, parent-child hierarchies may have only one level (plus the 'All' level).
 */
private String makeChildMemberSql_PCRoot(RolapMember member,Connection jdbcConnection){
  SqlQuery sqlQuery=newQuery(jdbcConnection,"String_Node_Str" + member);
  Util.assertTrue(member.isAll(),"String_Node_Str");
  RolapLevel level=(RolapLevel)member.getLevel().getChildLevel();
  Util.assertTrue(!level.isAll(),"String_Node_Str");
  Util.assertTrue(level.isUnique(),"String_Node_Str" + level + "String_Node_Str");
  hierarchy.addToFrom(sqlQuery,level.getParentExp());
  String parentId=level.getParentExp().getExpression(sqlQuery);
  StringBuffer condition=new StringBuffer(64);
  condition.append(parentId);
  if (level.getNullParentValue() == null || level.getNullParentValue().equalsIgnoreCase("String_Node_Str")) {
    condition.append("String_Node_Str");
  }
 else {
    try {
      Util.discard(Double.parseDouble(level.getNullParentValue()));
      condition.append("String_Node_Str");
      condition.append(level.getNullParentValue());
    }
 catch (    NumberFormatException e) {
      condition.append("String_Node_Str");
      Util.singleQuoteString(level.getNullParentValue(),condition);
    }
  }
  sqlQuery.addWhere(condition.toString());
  hierarchy.addToFrom(sqlQuery,level.getKeyExp());
  String childId=level.getKeyExp().getExpression(sqlQuery);
  sqlQuery.addSelect(childId);
  sqlQuery.addGroupBy(childId);
  hierarchy.addToFrom(sqlQuery,level.getOrdinalExp());
  String orderBy=level.getOrdinalExp().getExpression(sqlQuery);
  sqlQuery.addOrderBy(orderBy);
  if (!orderBy.equals(childId)) {
    sqlQuery.addGroupBy(orderBy);
  }
  RolapProperty[] properties=level.getRolapProperties();
  for (int j=0; j < properties.length; j++) {
    RolapProperty property=properties[j];
    final MondrianDef.Expression exp=property.getExp();
    hierarchy.addToFrom(sqlQuery,exp);
    final String s=exp.getExpression(sqlQuery);
    sqlQuery.addSelect(s);
    sqlQuery.addGroupBy(s);
  }
  return sqlQuery.toString();
}

Fixed version (ground truth):
/** 
 * Generates the SQL to find all root members of a parent-child hierarchy. For example, <blockquote> <pre>SELECT "employee_id" FROM "employee" WHERE "supervisor_id" IS NULL GROUP BY "employee_id"</pre> </blockquote> retrieves the root members of the <code>[Employee]</code> hierarchy. <p>Currently, parent-child hierarchies may have only one level (plus the 'All' level).
 */
private String makeChildMemberSql_PCRoot(RolapMember member,Connection jdbcConnection){
  SqlQuery sqlQuery=newQuery(jdbcConnection,"String_Node_Str" + member);
  Util.assertTrue(member.isAll(),"String_Node_Str");
  RolapLevel level=(RolapLevel)member.getLevel().getChildLevel();
  Util.assertTrue(!level.isAll(),"String_Node_Str");
  Util.assertTrue(level.isUnique(),"String_Node_Str" + level + "String_Node_Str");
  hierarchy.addToFrom(sqlQuery,level.getParentExp());
  String parentId=level.getParentExp().getExpression(sqlQuery);
  StringBuffer condition=new StringBuffer(64);
  condition.append(parentId);
  if (level.getNullParentValue() == null || level.getNullParentValue().equalsIgnoreCase("String_Node_Str")) {
    condition.append("String_Node_Str");
  }
 else {
    try {
      Util.discard(Double.parseDouble(level.getNullParentValue()));
      condition.append("String_Node_Str");
      condition.append(level.getNullParentValue());
    }
 catch (    NumberFormatException e) {
      condition.append("String_Node_Str");
      Util.singleQuoteString(level.getNullParentValue(),condition);
    }
  }
  sqlQuery.addWhere(condition.toString());
  hierarchy.addToFrom(sqlQuery,level.getKeyExp());
  String childId=level.getKeyExp().getExpression(sqlQuery);
  sqlQuery.addSelect(childId);
  sqlQuery.addGroupBy(childId);
  hierarchy.addToFrom(sqlQuery,level.getOrdinalExp());
  String orderBy=level.getOrdinalExp().getExpression(sqlQuery);
  sqlQuery.addOrderBy(orderBy,true,false);
  if (!orderBy.equals(childId)) {
    sqlQuery.addGroupBy(orderBy);
  }
  RolapProperty[] properties=level.getRolapProperties();
  for (int j=0; j < properties.length; j++) {
    RolapProperty property=properties[j];
    final MondrianDef.Expression exp=property.getExp();
    hierarchy.addToFrom(sqlQuery,exp);
    final String s=exp.getExpression(sqlQuery);
    sqlQuery.addSelect(s);
    sqlQuery.addGroupBy(s);
  }
  return sqlQuery.toString();
}