Program: 65267
Project: 65267
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);
    if (CrosstabUtil.isBoundToLinkedDataSet(crosstab)) {
      String dataField=CrosstabUtil.getRefLinkedDataModelColumnName(measureView);
      if (dataField == null || dataField.isEmpty()) {
        return;
      }
      column.setExpression(ExpressionUtil.createDataSetRowExpression(dataField));
    }
 else {
      column.setExpression(ExpressionUtil.createJSMeasureExpression(measureView.getCubeMeasureName()));
    }
    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) {
                ((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);
    if (CrosstabUtil.isBoundToLinkedDataSet(crosstab)) {
      String dataField=CrosstabUtil.getRefLinkedDataModelColumnName(measureView);
      if (dataField == null || dataField.trim().length() <= 0) {
        return;
      }
      column.setExpression(ExpressionUtil.createDataSetRowExpression(dataField));
    }
 else {
      column.setExpression(ExpressionUtil.createJSMeasureExpression(measureView.getCubeMeasureName()));
    }
    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) {
                ((DataItemHandle)item).setResultSetColumn(columnHandle.getName());
                break;
              }
            }
 catch (            BirtException e) {
            }
          }
        }
      }
    }
  }
}