Program: 50873
Project: 50873
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 Pair<String,List<SqlStatement.Type>> makeChildMemberSql_PCRoot(RolapMember member){
  SqlQuery sqlQuery=SqlQuery.newQuery(dataSource,"String_Node_Str" + "String_Node_Str" + member);
  Util.assertTrue(member.isAll(),"String_Node_Str" + "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);
  StringBuilder condition=new StringBuilder(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.addSelectGroupBy(childId,level.getInternalType());
  hierarchy.addToFrom(sqlQuery,level.getOrdinalExp());
  String orderBy=level.getOrdinalExp().getExpression(sqlQuery);
  sqlQuery.addOrderBy(orderBy,true,false,true);
  if (!orderBy.equals(childId)) {
    sqlQuery.addSelectGroupBy(orderBy,null);
  }
  RolapProperty[] properties=level.getProperties();
  for (  RolapProperty property : properties) {
    final MondrianDef.Expression exp=property.getExp();
    hierarchy.addToFrom(sqlQuery,exp);
    final String s=exp.getExpression(sqlQuery);
    String alias=sqlQuery.addSelect(s,null);
    if (!sqlQuery.getDialect().allowsSelectNotInGroupBy() || !property.dependsOnLevelValue()) {
      sqlQuery.addGroupBy(s,alias);
    }
  }
  return sqlQuery.toSqlAndTypes();
}

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 Pair<String,List<SqlStatement.Type>> makeChildMemberSql_PCRoot(RolapMember member){
  SqlQuery sqlQuery=SqlQuery.newQuery(dataSource,"String_Node_Str" + "String_Node_Str" + member);
  Util.assertTrue(member.isAll(),"String_Node_Str" + "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);
  StringBuilder condition=new StringBuilder(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());
  addLevel(sqlQuery,level,true);
  return sqlQuery.toSqlAndTypes();
}