Program: 51354
Project: 51354
Buggy source:
/** 
 * Make the measures for this aggregate table. <p> First, iterate through all of the columns in the table. For each column, iterate through all of the tableDef measures, the explicit definitions of a measure. If the table's column name matches the column name in the measure definition, then make a measure. Next, look through all of the fact table column usage measures. For each such measure usage that has a sibling foreign key usage see if the tableDef has a foreign key defined with the same name. If so, then, for free, we can make a measure for the aggregate using its foreign key. <p>
 * @return number of measures created.
 */
protected int checkMeasures(){
  msgRecorder.pushContextName("String_Node_Str");
  try {
    int measureColumnCounts=0;
    for (    JdbcSchema.Table.Column aggColumn : aggTable.getColumns()) {
      if (aggColumn.hasUsage(JdbcSchema.UsageType.IGNORE)) {
        continue;
      }
      String aggColumnName=aggColumn.getName();
      for (      ExplicitRules.TableDef.Measure measure : getTableDef().getMeasures()) {
        if (measure.getColumnName().equalsIgnoreCase(aggColumnName)) {
          String name=measure.getName();
          String[] parts=Util.explode(name);
          String nameLast=parts[parts.length - 1];
          RolapStar.Measure m=star.getFactTable().lookupMeasureByName(nameLast);
          RolapAggregator agg=null;
          if (m != null) {
            agg=m.getAggregator();
          }
          makeMeasure(measure,agg,aggColumn);
          measureColumnCounts++;
        }
      }
    }
    for (Iterator<JdbcSchema.Table.Column.Usage> it=dbFactTable.getColumnUsages(JdbcSchema.UsageType.MEASURE); it.hasNext(); ) {
      JdbcSchema.Table.Column.Usage factUsage=it.next();
      JdbcSchema.Table.Column factColumn=factUsage.getColumn();
      if (factColumn.hasUsage(JdbcSchema.UsageType.FOREIGN_KEY)) {
        String aggFK=getTableDef().getAggregateFK(factColumn.getName());
        if (aggFK != null) {
          JdbcSchema.Table.Column aggColumn=aggTable.getColumn(aggFK);
          if (aggColumn == null) {
            aggColumn=aggTable.getColumn(aggFK.toLowerCase());
          }
          if (aggColumn == null) {
            aggColumn=aggTable.getColumn(aggFK.toUpperCase());
          }
          if (aggColumn != null) {
            makeMeasure(factUsage,aggColumn);
            measureColumnCounts++;
          }
        }
      }
    }
    return measureColumnCounts;
  }
  finally {
    msgRecorder.popContextName();
  }
}

Fixed version (ground truth):
/** 
 * Make the measures for this aggregate table. <p> First, iterate through all of the columns in the table. For each column, iterate through all of the tableDef measures, the explicit definitions of a measure. If the table's column name matches the column name in the measure definition, then make a measure. Next, look through all of the fact table column usage measures. For each such measure usage that has a sibling foreign key usage see if the tableDef has a foreign key defined with the same name. If so, then, for free, we can make a measure for the aggregate using its foreign key. <p>
 * @return number of measures created.
 */
protected int checkMeasures(){
  msgRecorder.pushContextName("String_Node_Str");
  try {
    int measureColumnCounts=0;
    for (    JdbcSchema.Table.Column aggColumn : aggTable.getColumns()) {
      if (aggColumn.hasUsage(JdbcSchema.UsageType.IGNORE)) {
        continue;
      }
      String aggColumnName=aggColumn.getName();
      for (      ExplicitRules.TableDef.Measure measure : getTableDef().getMeasures()) {
        if (measure.getColumnName().equalsIgnoreCase(aggColumnName)) {
          String name=measure.getName();
          String[] parts=Util.explode(name);
          String nameLast=parts[parts.length - 1];
          RolapStar.Measure m=star.getFactTable().lookupMeasureByName(cube.getName(),nameLast);
          RolapAggregator agg=null;
          if (m != null) {
            agg=m.getAggregator();
          }
          makeMeasure(measure,agg,aggColumn);
          measureColumnCounts++;
        }
      }
    }
    for (Iterator<JdbcSchema.Table.Column.Usage> it=dbFactTable.getColumnUsages(JdbcSchema.UsageType.MEASURE); it.hasNext(); ) {
      JdbcSchema.Table.Column.Usage factUsage=it.next();
      JdbcSchema.Table.Column factColumn=factUsage.getColumn();
      if (factColumn.hasUsage(JdbcSchema.UsageType.FOREIGN_KEY)) {
        String aggFK=getTableDef().getAggregateFK(factColumn.getName());
        if (aggFK != null) {
          JdbcSchema.Table.Column aggColumn=aggTable.getColumn(aggFK);
          if (aggColumn == null) {
            aggColumn=aggTable.getColumn(aggFK.toLowerCase());
          }
          if (aggColumn == null) {
            aggColumn=aggTable.getColumn(aggFK.toUpperCase());
          }
          if (aggColumn != null) {
            makeMeasure(factUsage,aggColumn);
            measureColumnCounts++;
          }
        }
      }
    }
    return measureColumnCounts;
  }
  finally {
    msgRecorder.popContextName();
  }
}