Program: 66413
Project: 66413
Buggy source:
/** 
 * Populate the dimension.
 * @param cubeMaterializer
 * @param dim
 * @param stopSign
 * @return
 * @throws AdapterException 
 * @throws IOException
 * @throws BirtException
 * @throws DataException
 */
private IDimension populateDimension(CubeMaterializer cubeMaterializer,DimensionHandle dim,TabularCubeHandle cubeHandle,Map appContext,SecurityListener sl) throws AdapterException {
  List hiers=dim.getContents(DimensionHandle.HIERARCHIES_PROP);
  List iHiers=new ArrayList();
  for (int j=0; j < hiers.size(); j++) {
    TabularHierarchyHandle hierhandle=(TabularHierarchyHandle)hiers.get(0);
    List levels=hierhandle.getContents(TabularHierarchyHandle.LEVELS_PROP);
    List<ILevelDefn> levelInHier=new ArrayList<ILevelDefn>();
    List<String> leafLevelKeyColumn=new ArrayList<String>();
    Set<String> columnNamesForLevels=new HashSet<String>();
    for (int k=0; k < levels.size(); k++) {
      TabularLevelHandle level=(TabularLevelHandle)levels.get(k);
      columnNamesForLevels.add(level.getColumnName());
      List levelAttrs=new ArrayList();
      Iterator it=level.attributesIterator();
      while (it.hasNext()) {
        LevelAttributeHandle levelAttr=(LevelAttributeHandle)it.next();
        levelAttrs.add(OlapExpressionUtil.getAttributeColumnName(level.getName(),levelAttr.getName()));
      }
      if (DesignChoiceConstants.LEVEL_TYPE_DYNAMIC.equals(level.getLevelType()) && level.getDisplayColumnName() != null) {
        levelAttrs.add(OlapExpressionUtil.getDisplayColumnName(level.getName()));
      }
      leafLevelKeyColumn.add(level.getName());
      levelInHier.add(CubeElementFactory.createLevelDefinition(level.getName(),new String[]{level.getName()},this.toStringArray(levelAttrs)));
    }
    String[] jointHierarchyKeys=getJointHierarchyKeys(cubeHandle,hierhandle);
    if (!cubeHandle.autoPrimaryKey()) {
      for (      String jointKey : jointHierarchyKeys) {
        if (!columnNamesForLevels.contains(jointKey)) {
          throw new AdapterException(ResourceConstants.CUBE_JOINT_COLUMN_NOT_IN_LEVELS,new String[]{jointKey,dim.getName()});
        }
      }
    }
    if (levelInHier.size() >= 1) {
      if (cubeHandle.autoPrimaryKey() && jointHierarchyKeys.length > 0) {
        if (!Arrays.deepEquals(jointHierarchyKeys,new String[]{((TabularLevelHandle)levels.get(levels.size() - 1)).getColumnName()})) {
          levelInHier.add(CubeElementFactory.createLevelDefinition("String_Node_Str",getDummyLevelNamesForJointHierarchyKeys(jointHierarchyKeys),new String[0]));
        }
 else         if (levelInHier.size() > 1 && isDateTimeDimension(hierhandle)) {
          levelInHier.add(CubeElementFactory.createLevelDefinition("String_Node_Str",leafLevelKeyColumn.toArray(new String[0]),new String[0]));
        }
      }
 else       if (levelInHier.size() > 1) {
        levelInHier.add(CubeElementFactory.createLevelDefinition("String_Node_Str",leafLevelKeyColumn.toArray(new String[0]),new String[0]));
      }
    }
    Object originalMemCache=null;
    Object originalRowLimit=null;
    try {
      sl.process(dim);
      if (!(cubeHandle.getDataSet().equals(hierhandle.getDataSet()) || hierhandle.getDataSet() == null)) {
        originalMemCache=appContext.remove(DataEngine.MEMORY_DATA_SET_CACHE);
        originalRowLimit=appContext.remove(DataEngine.DATA_SET_CACHE_ROW_LIMIT);
      }
      IDatasetIterator valueIt=null;
      String[] timeType=getTimeLevelType(hierhandle);
      for (int i=0; i < timeType.length; i++) {
        levelInHier.get(i).setTimeType(timeType[i]);
      }
      if (!CubeHandleUtil.isTimeDimension(dim)) {
        valueIt=new DataSetIterator(this,cubeQueryMap.get(hierhandle),cubeMetaMap.get(hierhandle),appContext);
        ((DataSetIterator)valueIt).initSecurityListenerAndDimension(dim.getName(),sl);
      }
 else {
        valueIt=new TimeDimensionDatasetIterator(this,CubeHandleUtil.getStartTime(dim),CubeHandleUtil.getEndTime(dim),getFieldName(hierhandle),timeType);
      }
      iHiers.add(cubeMaterializer.createHierarchy(dim.getName(),hierhandle.getName(),valueIt,levelInHier.toArray(new ILevelDefn[0]),dataEngine.getSession().getStopSign()));
    }
 catch (    Exception e) {
      throw new AdapterException(ResourceConstants.CUBE_HIERARCHY_CREATION_ERROR,e,dim.getName() + "String_Node_Str" + hierhandle.getName());
    }
 finally {
      if (originalMemCache != null) {
        appContext.put(DataEngine.MEMORY_DATA_SET_CACHE,originalMemCache);
      }
      if (originalRowLimit != null) {
        appContext.put(DataEngine.DATA_SET_CACHE_ROW_LIMIT,originalRowLimit);
      }
    }
  }
  try {
    return cubeMaterializer.createDimension(dim.getName(),(IHierarchy)iHiers.get(0));
  }
 catch (  Exception e) {
    throw new AdapterException(ResourceConstants.CUBE_DIMENSION_CREATION_ERROR,e,dim.getName());
  }
}

Fixed version (ground truth):
/** 
 * Populate the dimension.
 * @param cubeMaterializer
 * @param dim
 * @param stopSign
 * @return
 * @throws AdapterException 
 * @throws IOException
 * @throws BirtException
 * @throws DataException
 */
private IDimension populateDimension(CubeMaterializer cubeMaterializer,DimensionHandle dim,TabularCubeHandle cubeHandle,Map appContext,SecurityListener sl) throws AdapterException {
  List hiers=dim.getContents(DimensionHandle.HIERARCHIES_PROP);
  List iHiers=new ArrayList();
  for (int j=0; j < hiers.size(); j++) {
    TabularHierarchyHandle hierhandle=(TabularHierarchyHandle)hiers.get(0);
    List levels=hierhandle.getContents(TabularHierarchyHandle.LEVELS_PROP);
    List<ILevelDefn> levelInHier=new ArrayList<ILevelDefn>();
    List<String> leafLevelKeyColumn=new ArrayList<String>();
    Set<String> columnNamesForLevels=new HashSet<String>();
    for (int k=0; k < levels.size(); k++) {
      TabularLevelHandle level=(TabularLevelHandle)levels.get(k);
      columnNamesForLevels.add(level.getColumnName());
      List levelAttrs=new ArrayList();
      Iterator it=level.attributesIterator();
      while (it.hasNext()) {
        LevelAttributeHandle levelAttr=(LevelAttributeHandle)it.next();
        levelAttrs.add(OlapExpressionUtil.getAttributeColumnName(level.getName(),levelAttr.getName()));
      }
      if (DesignChoiceConstants.LEVEL_TYPE_DYNAMIC.equals(level.getLevelType()) && level.getDisplayColumnName() != null) {
        levelAttrs.add(OlapExpressionUtil.getDisplayColumnName(level.getName()));
      }
      leafLevelKeyColumn.add(level.getName());
      levelInHier.add(CubeElementFactory.createLevelDefinition(level.getName(),new String[]{level.getName()},this.toStringArray(levelAttrs)));
    }
    String[] jointHierarchyKeys=getJointHierarchyKeys(cubeHandle,hierhandle);
    if (!cubeHandle.autoPrimaryKey()) {
      for (      String jointKey : jointHierarchyKeys) {
        if (!columnNamesForLevels.contains(jointKey)) {
          throw new AdapterException(ResourceConstants.CUBE_JOINT_COLUMN_NOT_IN_LEVELS,new String[]{jointKey,dim.getName()});
        }
      }
    }
    if (levelInHier.size() >= 1) {
      if (cubeHandle.autoPrimaryKey() && jointHierarchyKeys.length > 0) {
        if (!Arrays.deepEquals(jointHierarchyKeys,new String[]{((TabularLevelHandle)levels.get(levels.size() - 1)).getColumnName()})) {
          levelInHier.add(CubeElementFactory.createLevelDefinition("String_Node_Str",getDummyLevelNamesForJointHierarchyKeys(jointHierarchyKeys),new String[0]));
        }
 else         if (levelInHier.size() > 1 && isDateTimeDimension(hierhandle)) {
          levelInHier.add(CubeElementFactory.createLevelDefinition("String_Node_Str",leafLevelKeyColumn.toArray(new String[0]),new String[0]));
        }
      }
 else       if (levelInHier.size() > 1) {
        levelInHier.add(CubeElementFactory.createLevelDefinition("String_Node_Str",leafLevelKeyColumn.toArray(new String[0]),new String[0]));
      }
    }
    Object originalMemCache=null;
    Object originalRowLimit=null;
    try {
      sl.process(dim);
      if (!(cubeHandle.getDataSet().equals(hierhandle.getDataSet()) || hierhandle.getDataSet() == null)) {
        originalMemCache=appContext.remove(DataEngine.MEMORY_DATA_SET_CACHE);
        originalRowLimit=appContext.remove(DataEngine.DATA_SET_CACHE_ROW_LIMIT);
      }
      IDatasetIterator valueIt=null;
      String[] timeType=getTimeLevelType(hierhandle);
      for (int i=0; i < timeType.length; i++) {
        levelInHier.get(i).setTimeType(timeType[i]);
      }
      valueIt=new DataSetIterator(this,cubeQueryMap.get(hierhandle),cubeMetaMap.get(hierhandle),appContext);
      ((DataSetIterator)valueIt).initSecurityListenerAndDimension(dim.getName(),sl);
      iHiers.add(cubeMaterializer.createHierarchy(dim.getName(),hierhandle.getName(),valueIt,levelInHier.toArray(new ILevelDefn[0]),dataEngine.getSession().getStopSign()));
    }
 catch (    Exception e) {
      throw new AdapterException(ResourceConstants.CUBE_HIERARCHY_CREATION_ERROR,e,dim.getName() + "String_Node_Str" + hierhandle.getName());
    }
 finally {
      if (originalMemCache != null) {
        appContext.put(DataEngine.MEMORY_DATA_SET_CACHE,originalMemCache);
      }
      if (originalRowLimit != null) {
        appContext.put(DataEngine.DATA_SET_CACHE_ROW_LIMIT,originalRowLimit);
      }
    }
  }
  try {
    return cubeMaterializer.createDimension(dim.getName(),(IHierarchy)iHiers.get(0));
  }
 catch (  Exception e) {
    throw new AdapterException(ResourceConstants.CUBE_DIMENSION_CREATION_ERROR,e,dim.getName());
  }
}