Program: 66676
Project: 66676
Buggy source:
/** 
 * populate all output columns in viewer display. The output columns is retrieved from oda dataset handles's RESULT_SET_PROP and COMPUTED_COLUMNS_PROP.
 * @throws BirtException
 */
public static IResultMetaData retrieveResultMetaData(DataSetHandle dataSetHandle) throws BirtException {
  List resultSetList=null;
  boolean removeDuplicated=false;
  if (dataSetHandle instanceof OdaDataSetHandle) {
    PropertyHandle handle=dataSetHandle.getPropertyHandle(OdaDataSetHandle.RESULT_SET_PROP);
    resultSetList=handle.getListValue();
  }
 else   if (dataSetHandle instanceof ScriptDataSetHandle) {
    PropertyHandle handle=dataSetHandle.getPropertyHandle(DataSetHandle.RESULT_SET_HINTS_PROP);
    resultSetList=handle.getListValue();
  }
 else {
    resultSetList=MetaDataUtil.getResultPropertyHandle(dataSetHandle);
    removeDuplicated=true;
  }
  List computedList=(List)dataSetHandle.getProperty(OdaDataSetHandle.COMPUTED_COLUMNS_PROP);
  List columnMeta=new ArrayList();
  ResultSetColumnDefinition columnDef;
  int count=0;
  if (resultSetList != null && !resultSetList.isEmpty()) {
    ResultSetColumn resultSetColumn;
    HashSet orgColumnNameSet=new HashSet();
    HashSet uniqueColumnNameSet=new HashSet();
    for (int n=0; n < resultSetList.size(); n++) {
      orgColumnNameSet.add(((ResultSetColumn)resultSetList.get(n)).getColumnName());
    }
    for (int i=0; i < resultSetList.size(); i++) {
      resultSetColumn=(ResultSetColumn)resultSetList.get(i);
      uniqueColumnNameSet.add(resultSetColumn.getColumnName());
      columnDef=new ResultSetColumnDefinition(resultSetColumn.getColumnName());
      columnDef.setDataTypeName(resultSetColumn.getDataType());
      columnDef.setDataType(DataAdapterUtil.adaptModelDataType(resultSetColumn.getDataType()));
      if (resultSetColumn.getPosition() != null)       columnDef.setColumnPosition(resultSetColumn.getPosition().intValue());
      if (resultSetColumn.getNativeDataType() != null)       columnDef.setNativeDataType(resultSetColumn.getNativeDataType().intValue());
      if (findColumnHint(dataSetHandle,resultSetColumn.getColumnName()) != null) {
        ColumnHintHandle columnHint=findColumnHint(dataSetHandle,resultSetColumn.getColumnName());
        columnDef.setAlias(columnHint.getAlias());
        columnDef.setLableName(columnHint.getDisplayName());
      }
      columnDef.setComputedColumn(false);
      columnMeta.add(columnDef);
    }
    count+=resultSetList.size();
    if (computedList != null) {
      for (int n=0; n < computedList.size(); n++) {
        orgColumnNameSet.add(((ComputedColumn)computedList.get(n)).getName());
      }
      ComputedColumn computedColumn;
      for (int i=0; i < computedList.size(); i++) {
        computedColumn=(ComputedColumn)computedList.get(i);
        String columnName=computedColumn.getName();
        if (removeDuplicated) {
          if (uniqueColumnNameSet.contains(columnName))           continue;
        }
        String uniqueColumnName=getUniqueName(orgColumnNameSet,uniqueColumnNameSet,columnName,i + count);
        uniqueColumnNameSet.add(uniqueColumnName);
        if (!uniqueColumnName.equals(columnName)) {
          updateComputedColumn(dataSetHandle,uniqueColumnName,columnName);
        }
        columnDef=new ResultSetColumnDefinition(uniqueColumnName);
        columnDef.setDataTypeName(computedColumn.getDataType());
        columnDef.setDataType(org.eclipse.birt.report.data.adapter.api.DataAdapterUtil.adaptModelDataType(computedColumn.getDataType()));
        if (findColumnHint(dataSetHandle,uniqueColumnName) != null) {
          ColumnHintHandle columnHint=findColumnHint(dataSetHandle,uniqueColumnName);
          columnDef.setAlias(columnHint.getAlias());
          columnDef.setLableName(columnHint.getDisplayName());
        }
        columnDef.setComputedColumn(true);
        columnMeta.add(columnDef);
      }
    }
    return new ResultMetaData2(columnMeta);
  }
  return null;
}

Fixed version (ground truth):
/** 
 * populate all output columns in viewer display. The output columns is retrieved from oda dataset handles's RESULT_SET_PROP and COMPUTED_COLUMNS_PROP.
 * @throws BirtException
 */
public static IResultMetaData retrieveResultMetaData(DataSetHandle dataSetHandle) throws BirtException {
  List resultSetList=null;
  boolean removeDuplicated=false;
  if (dataSetHandle instanceof OdaDataSetHandle) {
    PropertyHandle handle=dataSetHandle.getPropertyHandle(OdaDataSetHandle.RESULT_SET_PROP);
    resultSetList=handle.getListValue();
  }
 else   if (dataSetHandle instanceof ScriptDataSetHandle) {
    PropertyHandle handle=dataSetHandle.getPropertyHandle(DataSetHandle.RESULT_SET_HINTS_PROP);
    resultSetList=handle.getListValue();
  }
 else {
    resultSetList=MetaDataUtil.getResultPropertyHandle(dataSetHandle);
    removeDuplicated=true;
  }
  List computedList=(List)dataSetHandle.getProperty(OdaDataSetHandle.COMPUTED_COLUMNS_PROP);
  List columnMeta=new ArrayList();
  ResultSetColumnDefinition columnDef;
  int count=0;
  if (resultSetList != null && !resultSetList.isEmpty()) {
    ResultSetColumn resultSetColumn;
    HashSet orgColumnNameSet=new HashSet();
    HashSet uniqueColumnNameSet=new HashSet();
    for (int n=0; n < resultSetList.size(); n++) {
      orgColumnNameSet.add(((ResultSetColumn)resultSetList.get(n)).getColumnName());
    }
    for (int i=0; i < resultSetList.size(); i++) {
      resultSetColumn=(ResultSetColumn)resultSetList.get(i);
      uniqueColumnNameSet.add(resultSetColumn.getColumnName());
      columnDef=new ResultSetColumnDefinition(resultSetColumn.getColumnName());
      columnDef.setDataTypeName(resultSetColumn.getDataType());
      columnDef.setDataType(DataAdapterUtil.adaptModelDataType(resultSetColumn.getDataType()));
      if (resultSetColumn.getPosition() != null)       columnDef.setColumnPosition(resultSetColumn.getPosition().intValue());
      if (resultSetColumn.getNativeDataType() != null)       columnDef.setNativeDataType(resultSetColumn.getNativeDataType().intValue());
      ColumnHintHandle columnHint=findColumnHint(dataSetHandle,resultSetColumn.getColumnName());
      if (columnHint != null) {
        columnDef.setAlias(columnHint.getAlias());
        columnDef.setLableName(columnHint.getDisplayName());
      }
      columnDef.setComputedColumn(false);
      columnMeta.add(columnDef);
    }
    count+=resultSetList.size();
    if (computedList != null) {
      for (int n=0; n < computedList.size(); n++) {
        orgColumnNameSet.add(((ComputedColumn)computedList.get(n)).getName());
      }
      ComputedColumn computedColumn;
      for (int i=0; i < computedList.size(); i++) {
        computedColumn=(ComputedColumn)computedList.get(i);
        String columnName=computedColumn.getName();
        if (removeDuplicated) {
          if (uniqueColumnNameSet.contains(columnName))           continue;
        }
        String uniqueColumnName=getUniqueName(orgColumnNameSet,uniqueColumnNameSet,columnName,i + count);
        uniqueColumnNameSet.add(uniqueColumnName);
        if (!uniqueColumnName.equals(columnName)) {
          updateComputedColumn(dataSetHandle,uniqueColumnName,columnName);
        }
        columnDef=new ResultSetColumnDefinition(uniqueColumnName);
        columnDef.setDataTypeName(computedColumn.getDataType());
        columnDef.setDataType(org.eclipse.birt.report.data.adapter.api.DataAdapterUtil.adaptModelDataType(computedColumn.getDataType()));
        if (findColumnHint(dataSetHandle,uniqueColumnName) != null) {
          ColumnHintHandle columnHint=findColumnHint(dataSetHandle,uniqueColumnName);
          columnDef.setAlias(columnHint.getAlias());
          columnDef.setLableName(columnHint.getDisplayName());
        }
        columnDef.setComputedColumn(true);
        columnMeta.add(columnDef);
      }
    }
    return new ResultMetaData2(columnMeta);
  }
  return null;
}