Program: 73978
Project: 73978
Buggy source:
/** 
 * @param axisType
 * @param measureList
 * @param functionList
 * @param isAdd
 * @param checkCounterAxis
 * @throws SemanticException
 */
protected void addMeasureAggregations(int axisType,List measureList,List functionList,boolean checkCounterAxis) throws SemanticException {
  if (crosstab == null || measureList == null || measureList.isEmpty() || crosstab.getGrandTotal(axisType) == null)   return;
  int counterAxisType=CrosstabModelUtil.getOppositeAxisType(axisType);
  String dimensionName=null;
  String levelName=null;
  boolean isCounterAxisEmpty=true;
  for (int dimension=0; dimension < crosstab.getDimensionCount(counterAxisType); dimension++) {
    DimensionViewHandle dimensionView=crosstab.getDimension(counterAxisType,dimension);
    for (int level=0; level < dimensionView.getLevelCount(); level++) {
      isCounterAxisEmpty=false;
      LevelViewHandle levelView=dimensionView.getLevel(level);
      String rowDimension=null;
      String rowLevel=null;
      String colDimension=null;
      String colLevel=null;
      if (counterAxisType == ROW_AXIS_TYPE) {
        rowDimension=dimensionView.getCubeDimensionName();
        rowLevel=levelView.getCubeLevelName();
        colDimension=dimensionName;
        colLevel=levelName;
      }
 else       if (counterAxisType == COLUMN_AXIS_TYPE) {
        rowDimension=dimensionName;
        rowLevel=levelName;
        colDimension=dimensionView.getCubeDimensionName();
        colLevel=levelView.getCubeLevelName();
      }
      if (levelView.isInnerMost() || levelView.getAggregationHeader() != null) {
        for (int i=0; i < measureList.size(); i++) {
          MeasureViewHandle measureView=(MeasureViewHandle)measureList.get(i);
          if (measureView.getCrosstab() != crosstab)           continue;
          String function=functionList == null ? DEFAULT_MEASURE_FUNCTION : (String)functionList.get(i);
          if (checkCounterAxis && !CrosstabModelUtil.isAggregationOn(measureView,levelView.getCubeLevelName(),counterAxisType))           continue;
          CrosstabModelUtil.addDataItem(crosstab,measureView,function,rowDimension,rowLevel,colDimension,colLevel);
        }
      }
    }
  }
  if (crosstab.getGrandTotal(counterAxisType) != null || isCounterAxisEmpty) {
    String rowDimension=null;
    String rowLevel=null;
    String colDimension=null;
    String colLevel=null;
    for (int i=0; i < measureList.size(); i++) {
      MeasureViewHandle measureView=(MeasureViewHandle)measureList.get(i);
      if (measureView.getCrosstab() != crosstab)       continue;
      String function=functionList == null ? DEFAULT_MEASURE_FUNCTION : (String)functionList.get(i);
      if (checkCounterAxis && !CrosstabModelUtil.isAggregationOn(measureView,null,counterAxisType))       continue;
      CrosstabModelUtil.addDataItem(crosstab,measureView,function,rowDimension,rowLevel,colDimension,colLevel);
    }
  }
}

Fixed version (ground truth):
/** 
 * @param axisType
 * @param measureList
 * @param functionList
 * @param isAdd
 * @param checkCounterAxis
 * @throws SemanticException
 */
protected void addMeasureAggregations(int axisType,List measureList,List functionList,boolean checkCounterAxis) throws SemanticException {
  if (crosstab == null || measureList == null || measureList.isEmpty() || crosstab.getGrandTotal(axisType) == null)   return;
  int counterAxisType=CrosstabModelUtil.getOppositeAxisType(axisType);
  String dimensionName=null;
  String levelName=null;
  boolean isCounterAxisEmpty=true;
  for (int dimension=0; dimension < crosstab.getDimensionCount(counterAxisType); dimension++) {
    DimensionViewHandle dimensionView=crosstab.getDimension(counterAxisType,dimension);
    for (int level=0; level < dimensionView.getLevelCount(); level++) {
      isCounterAxisEmpty=false;
      LevelViewHandle levelView=dimensionView.getLevel(level);
      String rowDimension=null;
      String rowLevel=null;
      String colDimension=null;
      String colLevel=null;
      if (counterAxisType == ROW_AXIS_TYPE) {
        rowDimension=dimensionView.getCubeDimensionName();
        rowLevel=levelView.getCubeLevelName();
        colDimension=dimensionName;
        colLevel=levelName;
      }
 else       if (counterAxisType == COLUMN_AXIS_TYPE) {
        rowDimension=dimensionName;
        rowLevel=levelName;
        colDimension=dimensionView.getCubeDimensionName();
        colLevel=levelView.getCubeLevelName();
      }
      if (levelView.isInnerMost() || levelView.getAggregationHeader() != null) {
        for (int i=0; i < measureList.size(); i++) {
          MeasureViewHandle measureView=(MeasureViewHandle)measureList.get(i);
          if (measureView.getCrosstab() != crosstab)           continue;
          String function=functionList == null ? CrosstabModelUtil.getDefaultMeasureAggregationFunction(measureView) : (String)functionList.get(i);
          if (checkCounterAxis && !CrosstabModelUtil.isAggregationOn(measureView,levelView.getCubeLevelName(),counterAxisType))           continue;
          CrosstabModelUtil.addDataItem(crosstab,measureView,function,rowDimension,rowLevel,colDimension,colLevel);
        }
      }
    }
  }
  if (crosstab.getGrandTotal(counterAxisType) != null || isCounterAxisEmpty) {
    String rowDimension=null;
    String rowLevel=null;
    String colDimension=null;
    String colLevel=null;
    for (int i=0; i < measureList.size(); i++) {
      MeasureViewHandle measureView=(MeasureViewHandle)measureList.get(i);
      if (measureView.getCrosstab() != crosstab)       continue;
      String function=functionList == null ? CrosstabModelUtil.getDefaultMeasureAggregationFunction(measureView) : (String)functionList.get(i);
      if (checkCounterAxis && !CrosstabModelUtil.isAggregationOn(measureView,null,counterAxisType))       continue;
      CrosstabModelUtil.addDataItem(crosstab,measureView,function,rowDimension,rowLevel,colDimension,colLevel);
    }
  }
}