Program: 68315
Project: 68315
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,Map<ReportElementHandle,QueryDefinition> queryMap,Map<ReportElementHandle,List<ColumnMeta>> metaMap) 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 levelKeys=new ArrayList();
      Iterator it=level.attributesIterator();
      while (it.hasNext()) {
        LevelAttributeHandle levelAttr=(LevelAttributeHandle)it.next();
        levelKeys.add(OlapExpressionUtil.getAttributeColumnName(level.getName(),levelAttr.getName()));
      }
      if (DesignChoiceConstants.LEVEL_TYPE_DYNAMIC.equals(level.getLevelType()) && level.getDisplayColumnName() != null) {
        levelKeys.add(OlapExpressionUtil.getDisplayColumnName(level.getName()));
      }
      leafLevelKeyColumn.add(level.getName());
      levelInHier.add(CubeElementFactory.createLevelDefinition(level.getName(),new String[]{level.getName()},this.toStringArray(levelKeys)));
    }
    String[] jointHierarchyKeys=getJointHierarchyKeys(cubeHandle,hierhandle);
    for (    String jointKey : jointHierarchyKeys) {
      if (!columnNamesForLevels.contains(jointKey)) {
        leafLevelKeyColumn.add(getDummyLevelNameForJointHierarchyKey(jointKey));
        levelInHier.add(CubeElementFactory.createLevelDefinition(getDummyLevelNameForJointHierarchyKey(jointKey),new String[]{getDummyLevelNameForJointHierarchyKey(jointKey)},new String[0]));
      }
    }
    if (levelInHier.size() > 1) {
      levelInHier.add(CubeElementFactory.createLevelDefinition("String_Node_Str",leafLevelKeyColumn.toArray(new String[0]),new String[0]));
    }
    Object rowLimit=appContext.get(DataEngine.MEMORY_DATA_SET_CACHE);
    try {
      if (rowLimit != null && !(cubeHandle.getDataSet().equals(hierhandle.getDataSet()) || hierhandle.getDataSet() == null)) {
        appContext.remove(DataEngine.MEMORY_DATA_SET_CACHE);
        iHiers.add(cubeMaterializer.createHierarchy(dim.getName(),hierhandle.getName(),new DataSetIterator(this,queryMap.get(hierhandle),metaMap.get(hierhandle),appContext),levelInHier.toArray(new ILevelDefn[0]),dataEngine.getSession().getStopSign()));
        appContext.put(DataEngine.MEMORY_DATA_SET_CACHE,rowLimit);
      }
 else {
        iHiers.add(cubeMaterializer.createHierarchy(dim.getName(),hierhandle.getName(),new DataSetIterator(this,queryMap.get(hierhandle),metaMap.get(hierhandle),appContext),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());
    }
  }
  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,Map<ReportElementHandle,QueryDefinition> queryMap,Map<ReportElementHandle,List<ColumnMeta>> metaMap,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 levelKeys=new ArrayList();
      Iterator it=level.attributesIterator();
      while (it.hasNext()) {
        LevelAttributeHandle levelAttr=(LevelAttributeHandle)it.next();
        levelKeys.add(OlapExpressionUtil.getAttributeColumnName(level.getName(),levelAttr.getName()));
      }
      if (DesignChoiceConstants.LEVEL_TYPE_DYNAMIC.equals(level.getLevelType()) && level.getDisplayColumnName() != null) {
        levelKeys.add(OlapExpressionUtil.getDisplayColumnName(level.getName()));
      }
      leafLevelKeyColumn.add(level.getName());
      levelInHier.add(CubeElementFactory.createLevelDefinition(level.getName(),new String[]{level.getName()},this.toStringArray(levelKeys)));
    }
    String[] jointHierarchyKeys=getJointHierarchyKeys(cubeHandle,hierhandle);
    for (    String jointKey : jointHierarchyKeys) {
      if (!columnNamesForLevels.contains(jointKey)) {
        leafLevelKeyColumn.add(getDummyLevelNameForJointHierarchyKey(jointKey));
        levelInHier.add(CubeElementFactory.createLevelDefinition(getDummyLevelNameForJointHierarchyKey(jointKey),new String[]{getDummyLevelNameForJointHierarchyKey(jointKey)},new String[0]));
      }
    }
    if (levelInHier.size() > 1) {
      levelInHier.add(CubeElementFactory.createLevelDefinition("String_Node_Str",leafLevelKeyColumn.toArray(new String[0]),new String[0]));
    }
    Object rowLimit=appContext.get(DataEngine.MEMORY_DATA_SET_CACHE);
    try {
      if (rowLimit != null && !(cubeHandle.getDataSet().equals(hierhandle.getDataSet()) || hierhandle.getDataSet() == null)) {
        appContext.remove(DataEngine.MEMORY_DATA_SET_CACHE);
        iHiers.add(cubeMaterializer.createHierarchy(dim.getName(),hierhandle.getName(),new DataSetIterator(this,queryMap.get(hierhandle),metaMap.get(hierhandle),appContext),levelInHier.toArray(new ILevelDefn[0]),dataEngine.getSession().getStopSign()));
        appContext.put(DataEngine.MEMORY_DATA_SET_CACHE,rowLimit);
      }
 else {
        iHiers.add(cubeMaterializer.createHierarchy(dim.getName(),hierhandle.getName(),new DataSetIterator(this,queryMap.get(hierhandle),metaMap.get(hierhandle),appContext),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());
    }
  }
  try {
    return cubeMaterializer.createDimension(dim.getName(),(IHierarchy)iHiers.get(0));
  }
 catch (  Exception e) {
    throw new AdapterException(ResourceConstants.CUBE_DIMENSION_CREATION_ERROR,e,dim.getName());
  }
}