Program: 65022
Project: 65022
Buggy source:
/** 
 * @param crosstab
 * @param measureView
 * @param function
 * @param rowDimension
 * @param rowLevel
 * @param colDimension
 * @param colLevel
 * @throws SemanticException
 */
public static void addDataItem(CrosstabReportItemHandle crosstab,AggregationCellHandle cell,MeasureViewHandle measureView,String function,String rowDimension,String rowLevel,String colDimension,String colLevel) throws SemanticException {
  if (crosstab == null || !needUpdateMeasure(measureView)) {
    return;
  }
  if (measureView instanceof ComputedMeasureViewHandle && !CrosstabUtil.isLinkedDataModelMeasureView(measureView)) {
    List<DataItemHandle> items=getDataItems(cell);
    for (int i=0; i < items.size(); i++) {
      updateRPTAggregateOn(crosstab,items.get(i));
    }
    return;
  }
  if (cell == null) {
    cell=measureView.getAggregationCell(rowDimension,rowLevel,colDimension,colLevel);
  }
  if (measureView instanceof ComputedMeasureViewHandle && !CrosstabUtil.isLinkedDataModelMeasureView(measureView)) {
    List<DataItemHandle> items=getDataItems(cell);
    for (int i=0; i < items.size(); i++) {
      updateRPTAggregateOn(crosstab,items.get(i));
    }
    return;
  }
  if (cell != null) {
    String name=generateComputedColumnName(measureView,colLevel,rowLevel);
    ComputedColumn column=StructureFactory.newComputedColumn(crosstab.getModelHandle(),name);
    String dataType=measureView.getDataType();
    column.setDataType(dataType);
    String measureName=null;
    if (CrosstabUtil.isBoundToLinkedDataSet(crosstab)) {
      measureName=CrosstabUtil.getRefLinkedDataModelColumnName(measureView);
      if (measureName == null || measureName.isEmpty()) {
        return;
      }
      column.setExpression(ExpressionUtil.createDataSetRowExpression(measureName));
    }
 else {
      measureName=measureView.getCubeMeasureName();
      column.setExpression(ExpressionUtil.createJSMeasureExpression(measureName));
    }
    String defaultFunction=getDefaultMeasureAggregationFunction(measureView);
    column.setAggregateFunction(function != null ? function : defaultFunction);
    if (function != null && !function.equalsIgnoreCase(defaultFunction)) {
      try {
        IAggrFunction aggFunc=getAggregationManager().getAggregation(column.getAggregateFunction());
        if (aggFunc.getType() == IAggrFunction.RUNNING_AGGR) {
          column.setAggregateFunction(defaultFunction);
        }
 else {
          String targetType=DataAdapterUtil.adapterToModelDataType(aggFunc.getDataType());
          if (!DesignChoiceConstants.COLUMN_DATA_TYPE_ANY.equals(targetType)) {
            column.setDataType(targetType);
          }
        }
      }
 catch (      BirtException e) {
      }
    }
    if (rowLevel != null) {
      column.addAggregateOn(rowLevel);
    }
    if (colLevel != null) {
      column.addAggregateOn(colLevel);
    }
    ComputedColumnHandle columnHandle=generateAggregation(crosstab,cell,measureView,function,rowDimension,rowLevel,colDimension,colLevel);
    if (columnHandle == null) {
      return;
    }
    if (cell.getContents().size() == 0) {
      DataItemHandle dataItem=crosstab.getModuleHandle().getElementFactory().newDataItem(null);
      dataItem.setResultSetColumn(columnHandle.getName());
      cell.addContent(dataItem);
    }
 else     if (cell.getContents().size() == 1 && cell.getContents().get(0) instanceof DataItemHandle) {
      DataItemHandle dataItem=(DataItemHandle)cell.getContents().get(0);
      dataItem.setResultSetColumn(columnHandle.getName());
    }
 else {
      for (      Object item : cell.getContents()) {
        if (item instanceof DataItemHandle) {
          String bindingName=((DataItemHandle)item).getResultSetColumn();
          ComputedColumnHandle binding=((ReportItemHandle)crosstab.getModelHandle()).findColumnBinding(bindingName);
          if (binding != null && binding.getAggregateFunction() != null) {
            try {
              IAggrFunction aggFunc=getAggregationManager().getAggregation(binding.getAggregateFunction());
              if (aggFunc.getType() != IAggrFunction.RUNNING_AGGR && isMeasureDataItem(crosstab,measureName,(DataItemHandle)item,binding)) {
                ((DataItemHandle)item).setResultSetColumn(columnHandle.getName());
                break;
              }
            }
 catch (            BirtException e) {
            }
          }
        }
      }
    }
  }
}

Fixed version (ground truth):
/** 
 * @param crosstab
 * @param measureView
 * @param function
 * @param rowDimension
 * @param rowLevel
 * @param colDimension
 * @param colLevel
 * @throws SemanticException
 */
public static void addDataItem(CrosstabReportItemHandle crosstab,AggregationCellHandle cell,MeasureViewHandle measureView,String function,String rowDimension,String rowLevel,String colDimension,String colLevel) throws SemanticException {
  if (crosstab == null || !needUpdateMeasure(measureView)) {
    return;
  }
  if (measureView instanceof ComputedMeasureViewHandle && !CrosstabUtil.isLinkedDataModelMeasureView(measureView)) {
    List<DataItemHandle> items=getDataItems(cell);
    for (int i=0; i < items.size(); i++) {
      updateRPTAggregateOn(crosstab,items.get(i));
    }
    return;
  }
  if (cell == null) {
    cell=measureView.getAggregationCell(rowDimension,rowLevel,colDimension,colLevel);
  }
  if (measureView instanceof ComputedMeasureViewHandle && !CrosstabUtil.isLinkedDataModelMeasureView(measureView)) {
    List<DataItemHandle> items=getDataItems(cell);
    for (int i=0; i < items.size(); i++) {
      updateRPTAggregateOn(crosstab,items.get(i));
    }
    return;
  }
  if (cell != null) {
    String name=generateComputedColumnName(measureView,colLevel,rowLevel);
    ComputedColumn column=StructureFactory.newComputedColumn(crosstab.getModelHandle(),name);
    String dataType=measureView.getDataType();
    column.setDataType(dataType);
    String measureName=null;
    if (CrosstabUtil.isBoundToLinkedDataSet(crosstab)) {
      measureName=CrosstabUtil.getRefLinkedDataModelColumnName(measureView);
      if (measureName == null || measureName.isEmpty()) {
        return;
      }
      column.setExpression(ExpressionUtil.createDataSetRowExpression(measureName));
    }
 else {
      measureName=measureView.getCubeMeasureName();
      column.setExpression(ExpressionUtil.createJSMeasureExpression(measureName));
    }
    String defaultFunction=getDefaultMeasureAggregationFunction(measureView);
    if (DesignChoiceConstants.MEASURE_FUNCTION_COUNT.equals(defaultFunction)) {
      dataType=DesignChoiceConstants.COLUMN_DATA_TYPE_INTEGER;
      column.setDataType(dataType);
    }
    column.setAggregateFunction(function != null ? function : defaultFunction);
    if (function != null && !function.equalsIgnoreCase(defaultFunction)) {
      try {
        IAggrFunction aggFunc=getAggregationManager().getAggregation(column.getAggregateFunction());
        if (aggFunc.getType() == IAggrFunction.RUNNING_AGGR) {
          column.setAggregateFunction(defaultFunction);
        }
 else {
          String targetType=DataAdapterUtil.adapterToModelDataType(aggFunc.getDataType());
          if (!DesignChoiceConstants.COLUMN_DATA_TYPE_ANY.equals(targetType)) {
            column.setDataType(targetType);
          }
        }
      }
 catch (      BirtException e) {
      }
    }
    if (rowLevel != null) {
      column.addAggregateOn(rowLevel);
    }
    if (colLevel != null) {
      column.addAggregateOn(colLevel);
    }
    ComputedColumnHandle columnHandle=generateAggregation(crosstab,cell,measureView,function,rowDimension,rowLevel,colDimension,colLevel);
    if (columnHandle == null) {
      return;
    }
    if (cell.getContents().size() == 0) {
      DataItemHandle dataItem=crosstab.getModuleHandle().getElementFactory().newDataItem(null);
      dataItem.setResultSetColumn(columnHandle.getName());
      cell.addContent(dataItem);
    }
 else     if (cell.getContents().size() == 1 && cell.getContents().get(0) instanceof DataItemHandle) {
      DataItemHandle dataItem=(DataItemHandle)cell.getContents().get(0);
      dataItem.setResultSetColumn(columnHandle.getName());
    }
 else {
      for (      Object item : cell.getContents()) {
        if (item instanceof DataItemHandle) {
          String bindingName=((DataItemHandle)item).getResultSetColumn();
          ComputedColumnHandle binding=((ReportItemHandle)crosstab.getModelHandle()).findColumnBinding(bindingName);
          if (binding != null && binding.getAggregateFunction() != null) {
            try {
              IAggrFunction aggFunc=getAggregationManager().getAggregation(binding.getAggregateFunction());
              if (aggFunc.getType() != IAggrFunction.RUNNING_AGGR && isMeasureDataItem(crosstab,measureName,(DataItemHandle)item,binding)) {
                ((DataItemHandle)item).setResultSetColumn(columnHandle.getName());
                break;
              }
            }
 catch (            BirtException e) {
            }
          }
        }
      }
    }
  }
}