Program: 73874
Project: 73874
Buggy source:
/** 
 * Get related level's info for all measure.
 * @param queryDefn
 * @return
 * @throws DataException 
 */
public static Map getRelationWithMeasure(ICubeQueryDefinition queryDefn) throws DataException {
  Map measureRelationMap=new HashMap();
  List rowLevelList=new ArrayList();
  List columnLevelList=new ArrayList();
  if (queryDefn.getEdge(ICubeQueryDefinition.COLUMN_EDGE) != null) {
    ILevelDefinition[] levels=getLevelsOnEdge(queryDefn.getEdge(ICubeQueryDefinition.COLUMN_EDGE));
    for (int i=0; i < levels.length; i++) {
      columnLevelList.add(new DimLevel(levels[i]));
    }
  }
  if (queryDefn.getEdge(ICubeQueryDefinition.ROW_EDGE) != null) {
    ILevelDefinition[] levels=getLevelsOnEdge(queryDefn.getEdge(ICubeQueryDefinition.ROW_EDGE));
    for (int i=0; i < levels.length; i++) {
      rowLevelList.add(new DimLevel(levels[i]));
    }
  }
  if (queryDefn.getMeasures() != null && !queryDefn.getMeasures().isEmpty()) {
    Iterator measureIter=queryDefn.getMeasures().iterator();
    while (measureIter.hasNext()) {
      IMeasureDefinition measure=(MeasureDefinition)measureIter.next();
      measureRelationMap.put(measure.getName(),new RelationShip(rowLevelList,columnLevelList));
    }
  }
  ICubeAggrDefn[] cubeAggrs=OlapExpressionUtil.getAggrDefns(queryDefn.getBindings());
  if (cubeAggrs != null && cubeAggrs.length > 0) {
    for (int i=0; i < cubeAggrs.length; i++) {
      if (cubeAggrs[i].getAggrName() == null)       continue;
      List aggrOns=cubeAggrs[i].getAggrLevels();
      List usedLevelOnRow=new ArrayList();
      List usedLevelOnColumn=new ArrayList();
      for (int j=0; j < aggrOns.size(); j++) {
        if (rowLevelList.contains(aggrOns.get(j)))         usedLevelOnRow.add(aggrOns.get(j));
 else         if (columnLevelList.contains(aggrOns.get(j)))         usedLevelOnColumn.add(aggrOns.get(j));
      }
      measureRelationMap.put(cubeAggrs[i].getName(),new RelationShip(usedLevelOnRow,usedLevelOnColumn));
    }
  }
  return measureRelationMap;
}

Fixed version (ground truth):
/** 
 * Get related level's info for all measure.
 * @param queryDefn
 * @param measureMapping 
 * @return
 * @throws DataException 
 */
public static Map getRelationWithMeasure(ICubeQueryDefinition queryDefn,Map measureMapping) throws DataException {
  Map measureRelationMap=new HashMap();
  List rowLevelList=new ArrayList();
  List columnLevelList=new ArrayList();
  if (queryDefn.getEdge(ICubeQueryDefinition.COLUMN_EDGE) != null) {
    ILevelDefinition[] levels=getLevelsOnEdge(queryDefn.getEdge(ICubeQueryDefinition.COLUMN_EDGE));
    for (int i=0; i < levels.length; i++) {
      columnLevelList.add(new DimLevel(levels[i]));
    }
  }
  if (queryDefn.getEdge(ICubeQueryDefinition.ROW_EDGE) != null) {
    ILevelDefinition[] levels=getLevelsOnEdge(queryDefn.getEdge(ICubeQueryDefinition.ROW_EDGE));
    for (int i=0; i < levels.length; i++) {
      rowLevelList.add(new DimLevel(levels[i]));
    }
  }
  if (queryDefn.getMeasures() != null && !queryDefn.getMeasures().isEmpty()) {
    Iterator measureIter=queryDefn.getMeasures().iterator();
    while (measureIter.hasNext()) {
      IMeasureDefinition measure=(MeasureDefinition)measureIter.next();
      measureRelationMap.put(measureMapping.get(measure.getName()),new RelationShip(rowLevelList,columnLevelList));
    }
  }
  ICubeAggrDefn[] cubeAggrs=OlapExpressionUtil.getAggrDefns(queryDefn.getBindings());
  if (cubeAggrs != null && cubeAggrs.length > 0) {
    for (int i=0; i < cubeAggrs.length; i++) {
      if (cubeAggrs[i].getAggrName() == null)       continue;
      List aggrOns=cubeAggrs[i].getAggrLevels();
      List usedLevelOnRow=new ArrayList();
      List usedLevelOnColumn=new ArrayList();
      for (int j=0; j < aggrOns.size(); j++) {
        if (rowLevelList.contains(aggrOns.get(j)))         usedLevelOnRow.add(aggrOns.get(j));
 else         if (columnLevelList.contains(aggrOns.get(j)))         usedLevelOnColumn.add(aggrOns.get(j));
      }
      measureRelationMap.put(cubeAggrs[i].getName(),new RelationShip(usedLevelOnRow,usedLevelOnColumn));
    }
  }
  return measureRelationMap;
}