Program: 68051
Project: 68051
Buggy source:
/** 
 * @param cubeHandle
 * @param cubeMaterializer
 * @param stopSign
 * @throws BirtException 
 * @throws IOException
 * @throws BirtException
 * @throws DataException
 */
private void createCube(TabularCubeHandle cubeHandle,CubeMaterializer cubeMaterializer,Map appContext) throws BirtException {
  SecurityListener sl=new SecurityListener(this);
  sl.start(cubeHandle);
  Map<?,?> backupAppContext=new HashMap();
  if (appContext == null)   appContext=new HashMap();
  backupAppContext.putAll(appContext);
  Map<ReportElementHandle,QueryDefinition> queryMap=new HashMap<ReportElementHandle,QueryDefinition>();
  Map<ReportElementHandle,List<ColumnMeta>> metaMap=new HashMap<ReportElementHandle,List<ColumnMeta>>();
  prepareForCubeGeneration(cubeHandle,queryMap,metaMap);
  List measureNames=new ArrayList();
  List measureGroups=cubeHandle.getContents(CubeHandle.MEASURE_GROUPS_PROP);
  for (int i=0; i < measureGroups.size(); i++) {
    MeasureGroupHandle mgh=(MeasureGroupHandle)measureGroups.get(i);
    List measures=mgh.getContents(MeasureGroupHandle.MEASURES_PROP);
    for (int j=0; j < measures.size(); j++) {
      MeasureHandle measure=(MeasureHandle)measures.get(j);
      measureNames.add(measure.getName());
    }
  }
  IDimension[] dimensions=populateDimensions(cubeMaterializer,cubeHandle,appContext,queryMap,metaMap,sl);
  String[][] factTableKey=new String[dimensions.length][];
  String[][] dimensionKey=new String[dimensions.length][];
  boolean fromJoin=false;
  for (int i=0; i < dimensions.length; i++) {
    TabularDimensionHandle dim=(TabularDimensionHandle)cubeHandle.getDimension(dimensions[i].getName());
    TabularHierarchyHandle hier=(TabularHierarchyHandle)dim.getDefaultHierarchy();
    if (cubeHandle.getDataSet().equals(hier.getDataSet()) || hier.getDataSet() == null) {
      String[] keyNames=dimensions[i].getHierarchy().getLevels()[dimensions[i].getHierarchy().getLevels().length - 1].getKeyNames();
      factTableKey[i]=keyNames;
      dimensionKey[i]=factTableKey[i];
    }
 else {
      fromJoin=true;
      Iterator it=cubeHandle.joinConditionsIterator();
      if (!it.hasNext())       throw new AdapterException(ResourceConstants.MISSING_JOIN_CONDITION,dim.getName());
      boolean foundJoinCondition=false;
      while (it.hasNext()) {
        DimensionConditionHandle dimCondHandle=(DimensionConditionHandle)it.next();
        if (dimCondHandle.getHierarchy().getName().equals(hier.getName())) {
          Iterator conditionIt=dimCondHandle.getJoinConditions().iterator();
          List dimensionKeys=new ArrayList();
          List factTableKeys=new ArrayList();
          while (conditionIt.hasNext()) {
            foundJoinCondition=true;
            DimensionJoinConditionHandle joinCondition=(DimensionJoinConditionHandle)conditionIt.next();
            String levelName=joinCondition.getLevelName();
            if (levelName != null && isAttribute(dimensions[i],levelName,joinCondition.getHierarchyKey())) {
              dimensionKeys.add(OlapExpressionUtil.getAttributeColumnName(getLevelName(dimensions[i],levelName),joinCondition.getHierarchyKey()));
            }
 else {
              String existLevelName=getLevelName(hier,joinCondition.getHierarchyKey());
              if (existLevelName != null) {
                dimensionKeys.add(existLevelName);
              }
 else {
                dimensionKeys.add(getDummyLevelNameForJointHierarchyKey(joinCondition.getHierarchyKey()));
              }
            }
            factTableKeys.add(OlapExpressionUtil.getQualifiedLevelName(dimensions[i].getName(),joinCondition.getCubeKey()));
          }
          factTableKey[i]=new String[factTableKeys.size()];
          dimensionKey[i]=new String[dimensionKeys.size()];
          for (int j=0; j < dimensionKeys.size(); j++) {
            factTableKey[i][j]=factTableKeys.get(j).toString();
            dimensionKey[i][j]=dimensionKeys.get(j).toString();
          }
        }
      }
      if (!foundJoinCondition)       throw new AdapterException(ResourceConstants.MISSING_JOIN_CONDITION,dim.getName());
    }
  }
  if (cubeHandle.autoPrimaryKey()) {
    QueryDefinition qd=queryMap.get(cubeHandle);
    if (!fromJoin) {
      List<ColumnMeta> metas=metaMap.get(cubeHandle);
      IBinding tempPKBinding=new Binding(DataSetIterator.createLevelName(getCubeTempPKDimensionName(cubeHandle),getCubeTempPKFieldName(cubeHandle)),new ScriptExpression("String_Node_Str"));
      qd.addBinding(tempPKBinding);
      DataSetIterator.ColumnMeta cm=new DataSetIterator.ColumnMeta(tempPKBinding.getBindingName(),null,DataSetIterator.ColumnMeta.LEVEL_KEY_TYPE);
      cm.setDataType(DataType.INTEGER_TYPE);
      metas.add(cm);
      dimensions=appendArray(dimensions,populateTempPKDimension(cubeMaterializer,cubeHandle,appContext));
      factTableKey=appendArray(factTableKey,new String[]{DataSetIterator.createLevelName(getCubeTempPKDimensionName(cubeHandle),getCubeTempPKFieldName(cubeHandle))});
      dimensionKey=appendArray(dimensionKey,new String[]{DataSetIterator.createLevelName(getCubeTempPKDimensionName(cubeHandle),getCubeTempPKFieldName(cubeHandle))});
    }
    for (    Object measureName : measureNames) {
      IBinding b=(IBinding)qd.getBindings().get(measureName);
      if (b != null) {
        b.setAggrFunction(null);
        if (b.getAggregatOns() != null) {
          b.getAggregatOns().clear();
        }
      }
    }
  }
  sl.end();
  try {
    cubeMaterializer.createCube(cubeHandle.getQualifiedName(),factTableKey,dimensionKey,dimensions,new DataSetIterator(this,queryMap.get(cubeHandle),metaMap.get(cubeHandle),appContext),this.toStringArray(measureNames),dataEngine.getSession().getStopSign());
  }
 catch (  Exception e) {
    throw new AdapterException(ResourceConstants.CUBE_MEASURE_CREATION_ERROR,e);
  }
  appContext.clear();
  appContext.putAll(backupAppContext);
}

Fixed version (ground truth):
/** 
 * @param cubeHandle
 * @param cubeMaterializer
 * @param stopSign
 * @throws BirtException 
 * @throws IOException
 * @throws BirtException
 * @throws DataException
 */
private void createCube(TabularCubeHandle cubeHandle,CubeMaterializer cubeMaterializer,Map appContext) throws BirtException {
  SecurityListener sl=new SecurityListener(this);
  sl.start(cubeHandle);
  Map<?,?> backupAppContext=new HashMap();
  if (appContext == null)   appContext=new HashMap();
  backupAppContext.putAll(appContext);
  Map<ReportElementHandle,QueryDefinition> queryMap=new HashMap<ReportElementHandle,QueryDefinition>();
  Map<ReportElementHandle,List<ColumnMeta>> metaMap=new HashMap<ReportElementHandle,List<ColumnMeta>>();
  prepareForCubeGeneration(cubeHandle,queryMap,metaMap);
  List measureNames=new ArrayList();
  List measureGroups=cubeHandle.getContents(CubeHandle.MEASURE_GROUPS_PROP);
  for (int i=0; i < measureGroups.size(); i++) {
    MeasureGroupHandle mgh=(MeasureGroupHandle)measureGroups.get(i);
    List measures=mgh.getContents(MeasureGroupHandle.MEASURES_PROP);
    for (int j=0; j < measures.size(); j++) {
      MeasureHandle measure=(MeasureHandle)measures.get(j);
      measureNames.add(measure.getName());
    }
  }
  IDimension[] dimensions=populateDimensions(cubeMaterializer,cubeHandle,appContext,queryMap,metaMap,sl);
  String[][] factTableKey=new String[dimensions.length][];
  String[][] dimensionKey=new String[dimensions.length][];
  boolean fromJoin=false;
  for (int i=0; i < dimensions.length; i++) {
    TabularDimensionHandle dim=(TabularDimensionHandle)cubeHandle.getDimension(dimensions[i].getName());
    TabularHierarchyHandle hier=(TabularHierarchyHandle)dim.getDefaultHierarchy();
    if (cubeHandle.getDataSet().equals(hier.getDataSet()) || hier.getDataSet() == null) {
      String[] keyNames=dimensions[i].getHierarchy().getLevels()[dimensions[i].getHierarchy().getLevels().length - 1].getKeyNames();
      factTableKey[i]=new String[keyNames.length];
      dimensionKey[i]=new String[keyNames.length];
      for (int j=0; j < keyNames.length; j++) {
        factTableKey[i][j]=dim.getName() + "String_Node_Str" + keyNames[j];
        dimensionKey[i][j]=keyNames[j];
      }
    }
 else {
      fromJoin=true;
      Iterator it=cubeHandle.joinConditionsIterator();
      if (!it.hasNext())       throw new AdapterException(ResourceConstants.MISSING_JOIN_CONDITION,dim.getName());
      boolean foundJoinCondition=false;
      while (it.hasNext()) {
        DimensionConditionHandle dimCondHandle=(DimensionConditionHandle)it.next();
        if (dimCondHandle.getHierarchy().getName().equals(hier.getName())) {
          Iterator conditionIt=dimCondHandle.getJoinConditions().iterator();
          List dimensionKeys=new ArrayList();
          List factTableKeys=new ArrayList();
          while (conditionIt.hasNext()) {
            foundJoinCondition=true;
            DimensionJoinConditionHandle joinCondition=(DimensionJoinConditionHandle)conditionIt.next();
            String levelName=joinCondition.getLevelName();
            if (levelName != null && isAttribute(dimensions[i],levelName,joinCondition.getHierarchyKey())) {
              dimensionKeys.add(OlapExpressionUtil.getAttributeColumnName(getLevelName(dimensions[i],levelName),joinCondition.getHierarchyKey()));
            }
 else {
              String existLevelName=getLevelName(hier,joinCondition.getHierarchyKey());
              if (existLevelName != null) {
                dimensionKeys.add(existLevelName);
              }
 else {
                dimensionKeys.add(getDummyLevelNameForJointHierarchyKey(joinCondition.getHierarchyKey()));
              }
            }
            factTableKeys.add(OlapExpressionUtil.getQualifiedLevelName(dimensions[i].getName(),joinCondition.getCubeKey()));
          }
          factTableKey[i]=new String[factTableKeys.size()];
          dimensionKey[i]=new String[dimensionKeys.size()];
          for (int j=0; j < dimensionKeys.size(); j++) {
            factTableKey[i][j]=factTableKeys.get(j).toString();
            dimensionKey[i][j]=dimensionKeys.get(j).toString();
          }
        }
      }
      if (!foundJoinCondition)       throw new AdapterException(ResourceConstants.MISSING_JOIN_CONDITION,dim.getName());
    }
  }
  if (cubeHandle.autoPrimaryKey()) {
    QueryDefinition qd=queryMap.get(cubeHandle);
    if (!fromJoin) {
      List<ColumnMeta> metas=metaMap.get(cubeHandle);
      IBinding tempPKBinding=new Binding(DataSetIterator.createLevelName(getCubeTempPKDimensionName(cubeHandle),getCubeTempPKFieldName(cubeHandle)),new ScriptExpression("String_Node_Str"));
      qd.addBinding(tempPKBinding);
      DataSetIterator.ColumnMeta cm=new DataSetIterator.ColumnMeta(tempPKBinding.getBindingName(),null,DataSetIterator.ColumnMeta.LEVEL_KEY_TYPE);
      cm.setDataType(DataType.INTEGER_TYPE);
      metas.add(cm);
      dimensions=appendArray(dimensions,populateTempPKDimension(cubeMaterializer,cubeHandle,appContext));
      factTableKey=appendArray(factTableKey,new String[]{DataSetIterator.createLevelName(getCubeTempPKDimensionName(cubeHandle),getCubeTempPKFieldName(cubeHandle))});
      dimensionKey=appendArray(dimensionKey,new String[]{DataSetIterator.createLevelName(getCubeTempPKDimensionName(cubeHandle),getCubeTempPKFieldName(cubeHandle))});
    }
    for (    Object measureName : measureNames) {
      IBinding b=(IBinding)qd.getBindings().get(measureName);
      if (b != null) {
        b.setAggrFunction(null);
        if (b.getAggregatOns() != null) {
          b.getAggregatOns().clear();
        }
      }
    }
  }
  sl.end();
  try {
    cubeMaterializer.createCube(cubeHandle.getQualifiedName(),factTableKey,dimensionKey,dimensions,new DataSetIterator(this,queryMap.get(cubeHandle),metaMap.get(cubeHandle),appContext),this.toStringArray(measureNames),dataEngine.getSession().getStopSign());
  }
 catch (  Exception e) {
    throw new AdapterException(ResourceConstants.CUBE_MEASURE_CREATION_ERROR,e);
  }
  appContext.clear();
  appContext.putAll(backupAppContext);
}