Program: 69777
Project: 69777
Buggy source:
/** 
 * Returns if aggregation is needed on given level on specific axis, this is mainly to check if there's any existing aggregation cell on given level subtotal or grantotal(given level view is null). One special case is the given axis area is blank(so level view is also null), in this case, we need check subtotal and grandtotal on couter axis.
 * @param measureView
 * @param levelView
 * @param axisType
 * @return
 */
private boolean isAggregationNeeded(MeasureViewHandle measureView,LevelViewHandle levelView,int axisType,List<LevelViewHandle> counterAggregationLevels){
  if (measureView != null) {
    String checkDimensionName=null;
    String checkLevelName=null;
    if (levelView != null) {
      checkDimensionName=((DimensionViewHandle)levelView.getContainer()).getCubeDimensionName();
      checkLevelName=levelView.getCubeLevelName();
    }
    int counterAxisType=CrosstabModelUtil.getOppositeAxisType(axisType);
    boolean isInnerMost=levelView != null ? levelView.isInnerMost() : false;
    int totalDimensions=crosstab.getDimensionCount(axisType);
    if (isInnerMost || totalDimensions == 0) {
      if (counterAggregationLevels.size() > 0) {
        return true;
      }
      if (crosstab.getGrandTotal(counterAxisType) != null) {
        return true;
      }
    }
    int totalCounterDimensions=crosstab.getDimensionCount(counterAxisType);
    if (totalCounterDimensions > 0) {
      for (int i=0; i < totalCounterDimensions; i++) {
        DimensionViewHandle dv=crosstab.getDimension(counterAxisType,i);
        int totalLevels=dv.getLevelCount();
        for (int j=0; j < totalLevels; j++) {
          LevelViewHandle lv=dv.getLevel(j);
          if ((i == totalCounterDimensions - 1 && j == totalLevels - 1) || lv.getAggregationHeader() != null) {
            AggregationCellHandle cell=null;
            if (axisType == ROW_AXIS_TYPE) {
              cell=measureView.getAggregationCell(checkDimensionName,checkLevelName,dv.getCubeDimensionName(),lv.getCubeLevelName());
            }
 else {
              cell=measureView.getAggregationCell(dv.getCubeDimensionName(),lv.getCubeLevelName(),checkDimensionName,checkLevelName);
            }
            if (cell != null) {
              return true;
            }
          }
        }
      }
    }
    if (totalCounterDimensions == 0 || crosstab.getGrandTotal(counterAxisType) != null) {
      AggregationCellHandle cell=null;
      if (axisType == ROW_AXIS_TYPE) {
        cell=measureView.getAggregationCell(checkDimensionName,checkLevelName,null,null);
      }
 else {
        cell=measureView.getAggregationCell(null,null,checkDimensionName,checkLevelName);
      }
      if (cell != null) {
        return true;
      }
    }
  }
  return false;
}

Fixed version (ground truth):
/** 
 * Returns if aggregation is needed on given level on specific axis, this is mainly to check if there's any existing aggregation cell on given level subtotal or grantotal(if given level view is null). One special case is the given axis area is blank(so level view is also null), in this case, we need check subtotal and grandtotal on couter axis.
 * @param measureView
 * @param levelView
 * @param axisType
 * @return
 */
private boolean isAggregationNeeded(MeasureViewHandle measureView,LevelViewHandle levelView,int axisType,List<LevelViewHandle> counterAggregationLevels){
  if (measureView != null) {
    String checkDimensionName=null;
    String checkLevelName=null;
    if (levelView != null) {
      checkDimensionName=((DimensionViewHandle)levelView.getContainer()).getCubeDimensionName();
      checkLevelName=levelView.getCubeLevelName();
    }
    int counterAxisType=CrosstabModelUtil.getOppositeAxisType(axisType);
    boolean isInnerMost=levelView != null ? levelView.isInnerMost() : false;
    int totalDimensions=crosstab.getDimensionCount(axisType);
    if (isInnerMost || totalDimensions == 0) {
      if (counterAggregationLevels.size() > 0) {
        return true;
      }
      if (crosstab.getGrandTotal(counterAxisType) != null) {
        return true;
      }
    }
    int totalCounterDimensions=crosstab.getDimensionCount(counterAxisType);
    if (totalCounterDimensions > 0) {
      for (int i=0; i < totalCounterDimensions; i++) {
        DimensionViewHandle dv=crosstab.getDimension(counterAxisType,i);
        int totalLevels=dv.getLevelCount();
        for (int j=0; j < totalLevels; j++) {
          LevelViewHandle lv=dv.getLevel(j);
          if ((i == totalCounterDimensions - 1 && j == totalLevels - 1) || lv.getAggregationHeader() != null) {
            AggregationCellHandle cell=null;
            if (axisType == ROW_AXIS_TYPE) {
              cell=measureView.getAggregationCell(checkDimensionName,checkLevelName,dv.getCubeDimensionName(),lv.getCubeLevelName());
            }
 else {
              cell=measureView.getAggregationCell(dv.getCubeDimensionName(),lv.getCubeLevelName(),checkDimensionName,checkLevelName);
            }
            if (cell != null) {
              return true;
            }
          }
        }
      }
    }
    if (totalCounterDimensions == 0 || crosstab.getGrandTotal(counterAxisType) != null) {
      AggregationCellHandle cell=null;
      if (axisType == ROW_AXIS_TYPE) {
        cell=measureView.getAggregationCell(checkDimensionName,checkLevelName,null,null);
      }
 else {
        cell=measureView.getAggregationCell(null,null,checkDimensionName,checkLevelName);
      }
      if (cell != null) {
        return true;
      }
    }
  }
  return false;
}