Program: 51683
Project: 51683
Buggy source:
/** 
 * Adds to the FROM clause of the query the tables necessary to access the members of this hierarchy. If <code>level</code> is not null, adds only the tables necessary to access that level (which may be fewer tables). <p> This method is idempotent: if you call it more than once, it onle adds the table(s) to the FROM clause once.
 * @param query Query to add the hierarchy to
 * @param level Level to qualify up to; if null, qualifies up to thetopmost ('all') level, which may require more columns and more joins
 * @param cube If not null, include the cube's fact table in the query andjoin to it. Member readers generally do not want to join the cube, but measure readers do.
 */
void addToFrom(SqlQuery query,RolapLevel level,RolapCube cube){
  if (xmlHierarchy == null) {
    throw Util.newError("String_Node_Str" + getUniqueName() + "String_Node_Str");
  }
  final boolean failIfExists=false;
  if (cube != null) {
    HierarchyUsage hierarchyUsage=getSchema().getUsage(this,cube);
    query.addFrom(cube.getFact(),failIfExists);
    query.addFrom(hierarchyUsage.primaryKeyTable,failIfExists);
    query.addWhere(query.quoteIdentifier(cube.getAlias(),hierarchyUsage.foreignKey) + "String_Node_Str" + query.quoteIdentifier(hierarchyUsage.primaryKeyTable.getAlias(),hierarchyUsage.primaryKey));
  }
  MondrianDef.Relation relation=xmlHierarchy.relation;
  if (relation instanceof MondrianDef.Join) {
    MondrianDef.Join join=(MondrianDef.Join)relation;
    if (level != null) {
      relation=relationSubset(relation,level.nameExp.getTableAlias());
    }
  }
  query.addFrom(relation,failIfExists);
}

Fixed version (ground truth):
/** 
 * Adds to the FROM clause of the query the tables necessary to access the members of this hierarchy. If <code>expression</code> is not null, adds the tables necessary to compute that expression. <p> This method is idempotent: if you call it more than once, it only adds the table(s) to the FROM clause once.
 * @param query Query to add the hierarchy to
 * @param expression Level to qualify up to; if null, qualifies up to thetopmost ('all') expression, which may require more columns and more joins
 * @param cube If not null, include the cube's fact table in the query andjoin to it. Member readers generally do not want to join the cube, but measure readers do.
 */
void addToFrom(SqlQuery query,MondrianDef.Expression expression,RolapCube cube){
  if (xmlHierarchy == null) {
    throw Util.newError("String_Node_Str" + getUniqueName() + "String_Node_Str");
  }
  final boolean failIfExists=false;
  if (cube != null) {
    HierarchyUsage hierarchyUsage=getSchema().getUsage(this,cube);
    query.addFrom(cube.getFact(),failIfExists);
    query.addFrom(hierarchyUsage.primaryKeyTable,failIfExists);
    query.addWhere(query.quoteIdentifier(cube.getAlias(),hierarchyUsage.foreignKey) + "String_Node_Str" + query.quoteIdentifier(hierarchyUsage.primaryKeyTable.getAlias(),hierarchyUsage.primaryKey));
  }
  MondrianDef.Relation relation=xmlHierarchy.relation;
  if (relation instanceof MondrianDef.Join) {
    if (expression != null) {
      relation=relationSubset(relation,expression.getTableAlias());
    }
  }
  query.addFrom(relation,failIfExists);
}