Program: 75845
Project: 75845
Buggy source:
/** 
 * Populate the dimension.
 * @param cubeMaterializer
 * @param dim
 * @return
 * @throws IOException
 * @throws BirtException
 * @throws DataException
 */
private IDimension populateDimension(CubeMaterializer cubeMaterializer,DimensionHandle dim,TabularCubeHandle cubeHandle,Map extraTimeLevelHolder) throws IOException, BirtException, DataException {
  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);
    boolean shareFactTable=cubeHandle.getDataSet().equals(hierhandle.getDataSet());
    ILevelDefn[] levelInHier=null;
    String timeLevelName=null;
    int timeLevelOffset=0;
    if (dim.isTimeType()) {
      TabularLevelHandle level=(TabularLevelHandle)hierhandle.getContents(TabularHierarchyHandle.LEVELS_PROP).get(0);
      timeLevelName=level.getColumnName();
      timeLevelOffset=1;
      extraTimeLevelHolder.put(dim,timeLevelName);
    }
    String leafLevelName=null;
    if (!shareFactTable) {
      Iterator it=cubeHandle.joinConditionsIterator();
      while (it.hasNext()) {
        DimensionConditionHandle dimCondHandle=(DimensionConditionHandle)it.next();
        if (dimCondHandle.getHierarchy().equals(hierhandle)) {
          DimensionJoinConditionHandle joinCondition=(DimensionJoinConditionHandle)dimCondHandle.getJoinConditions().iterator().next();
          leafLevelName=joinCondition.getHierarchyKey();
          if (hierhandle.getLevel(leafLevelName) != null && !leafLevelName.equals(timeLevelName)) {
            if (!(hierhandle.getLevel(hierhandle.getLevelCount() - 1).equals(hierhandle.getLevel(leafLevelName)))) {
              throw new AdapterException("String_Node_Str");
            }
            levelInHier=new ILevelDefn[hierhandle.getLevelCount() + timeLevelOffset];
            leafLevelName=null;
          }
 else {
            levelInHier=new ILevelDefn[hierhandle.getLevelCount() + 1 + timeLevelOffset];
          }
        }
      }
    }
 else {
      levelInHier=new ILevelDefn[hierhandle.getLevelCount() + timeLevelOffset];
    }
    for (int k=0; k < levels.size(); k++) {
      TabularLevelHandle level=(TabularLevelHandle)levels.get(k);
      List levelKeys=new ArrayList();
      Iterator it=level.attributesIterator();
      while (it.hasNext()) {
        LevelAttributeHandle levelAttr=(LevelAttributeHandle)it.next();
        levelKeys.add(level.getName() + "String_Node_Str" + levelAttr.getName());
      }
      levelInHier[k]=CubeElementFactory.createLevelDefinition(level.getName(),new String[]{level.getName()},this.toStringArray(levelKeys));
    }
    if (timeLevelName != null) {
      int index=0;
      if (leafLevelName != null)       index=levelInHier.length - 2;
 else       index=levelInHier.length - 1;
      levelInHier[index]=CubeElementFactory.createLevelDefinition(timeLevelName,new String[]{timeLevelName},new String[0]);
    }
    if (leafLevelName != null) {
      levelInHier[levelInHier.length - 1]=CubeElementFactory.createLevelDefinition(leafLevelName,new String[]{leafLevelName},new String[0]);
    }
    iHiers.add(cubeMaterializer.createHierarchy(hierhandle.getName(),new DataSetIterator(this,hierhandle,timeLevelName,leafLevelName),levelInHier));
  }
  return cubeMaterializer.createDimension(dim.getName(),(IHierarchy)iHiers.get(0));
}

Fixed version (ground truth):
/** 
 * Populate the dimension.
 * @param cubeMaterializer
 * @param dim
 * @return
 * @throws IOException
 * @throws BirtException
 * @throws DataException
 */
private IDimension populateDimension(CubeMaterializer cubeMaterializer,DimensionHandle dim,TabularCubeHandle cubeHandle,Map extraTimeLevelHolder) throws IOException, BirtException, DataException {
  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);
    boolean shareFactTable=cubeHandle.getDataSet().equals(hierhandle.getDataSet());
    ILevelDefn[] levelInHier=null;
    String timeLevelName=null;
    int timeLevelOffset=0;
    if (dim.isTimeType()) {
      TabularLevelHandle level=(TabularLevelHandle)hierhandle.getContents(TabularHierarchyHandle.LEVELS_PROP).get(0);
      timeLevelName=level.getColumnName();
      timeLevelOffset=1;
      extraTimeLevelHolder.put(dim,timeLevelName);
    }
    String leafLevelName=null;
    if (!shareFactTable) {
      Iterator it=cubeHandle.joinConditionsIterator();
      while (it.hasNext()) {
        DimensionConditionHandle dimCondHandle=(DimensionConditionHandle)it.next();
        if (dimCondHandle.getHierarchy().equals(hierhandle)) {
          DimensionJoinConditionHandle joinCondition=(DimensionJoinConditionHandle)dimCondHandle.getJoinConditions().iterator().next();
          leafLevelName=joinCondition.getHierarchyKey();
          if (hierhandle.getLevel(leafLevelName) != null && !leafLevelName.equals(timeLevelName)) {
            if (!(hierhandle.getLevel(hierhandle.getLevelCount() - 1).equals(hierhandle.getLevel(leafLevelName)))) {
              throw new AdapterException("String_Node_Str");
            }
            levelInHier=new ILevelDefn[hierhandle.getLevelCount() + timeLevelOffset];
            leafLevelName=null;
          }
 else {
            levelInHier=new ILevelDefn[hierhandle.getLevelCount() + 1 + timeLevelOffset];
          }
        }
      }
      if (levelInHier == null)       throw new DataException("String_Node_Str");
    }
 else {
      levelInHier=new ILevelDefn[hierhandle.getLevelCount() + timeLevelOffset];
    }
    for (int k=0; k < levels.size(); k++) {
      TabularLevelHandle level=(TabularLevelHandle)levels.get(k);
      List levelKeys=new ArrayList();
      Iterator it=level.attributesIterator();
      while (it.hasNext()) {
        LevelAttributeHandle levelAttr=(LevelAttributeHandle)it.next();
        levelKeys.add(level.getName() + "String_Node_Str" + levelAttr.getName());
      }
      levelInHier[k]=CubeElementFactory.createLevelDefinition(level.getName(),new String[]{level.getName()},this.toStringArray(levelKeys));
    }
    if (timeLevelName != null) {
      int index=0;
      if (leafLevelName != null)       index=levelInHier.length - 2;
 else       index=levelInHier.length - 1;
      levelInHier[index]=CubeElementFactory.createLevelDefinition(timeLevelName,new String[]{timeLevelName},new String[0]);
    }
    if (leafLevelName != null) {
      levelInHier[levelInHier.length - 1]=CubeElementFactory.createLevelDefinition(leafLevelName,new String[]{leafLevelName},new String[0]);
    }
    iHiers.add(cubeMaterializer.createHierarchy(hierhandle.getName(),new DataSetIterator(this,hierhandle,timeLevelName,leafLevelName),levelInHier));
  }
  return cubeMaterializer.createDimension(dim.getName(),(IHierarchy)iHiers.get(0));
}