Program: 69776
Project: 69776
Buggy source:
/** 
 * @param axisType
 * @param measureList
 * @param functionList
 * @param isAdd
 * @param checkCounterAxis
 * @throws SemanticException
 */
protected void addMeasureAggregations(int axisType,List<MeasureViewHandle> measureList,List<String> 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=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=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);
    }
  }
}

Fixed version (ground truth):
/** 
 * This method checks and adds the missing aggregations for given measures on the specific axis(grand total). Note if <code>checkCounterAxis</code> is <code>true</code>, in certain cases, the check in this method will be skipped, and the remaining work is expected to be done in subsequent <code>validateCrosstab</code>.
 * @param axisType
 * @param measureList
 * @param functionList
 * @param isAdd
 * @param checkCounterAxis
 * @throws SemanticException
 */
protected void addMeasureAggregations(int axisType,List<MeasureViewHandle> measureList,List<String> 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=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=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);
    }
  }
}