Program: 65974
Project: 65974
Buggy source:
/** 
 * @param levelDefs
 * @param keyDataType
 * @param attributesDataType
 * @param sortedDimensionSet
 * @param stopSign
 * @throws IOException
 * @throws BirtException
 */
private int saveHierarchyRows(ILevelDefn[] levelDefs,int[][] keyDataType,int[][] attributesDataType,DiskSortedStack sortedDimensionSet,StopSign stopSign) throws IOException, BirtException {
  DiskSortedStack sortedDimMembers=new DiskSortedStack(Math.min(sortedDimensionSet.size(),Constants.MAX_LIST_BUFFER_SIZE),true,false,Member.getCreator());
  IDiskArray[] indexKeyLists=new IDiskArray[keyDataType.length];
  for (int i=0; i < indexKeyLists.length; i++) {
    indexKeyLists[i]=new BufferedStructureArray(IndexKey.getCreator(),Math.min(sortedDimensionSet.size(),Constants.MAX_LIST_BUFFER_SIZE));
  }
  Object obj=sortedDimensionSet.pop();
  int currentIndex=0;
  IndexKey indexKey=null;
  while (obj != null) {
    if (stopSign.isStopped())     break;
    DimensionRow dimRows=(DimensionRow)obj;
    Member[] levelMembers=dimRows.getMembers();
    for (int i=0; i < indexKeyLists.length; i++) {
      indexKey=new IndexKey();
      indexKey.setKey(levelMembers[i].getKeyValues());
      indexKey.setOffset(new int[]{(int)documentObj.getFilePointer()});
      indexKey.setDimensionPos(new int[]{currentIndex});
      indexKeyLists[i].add(indexKey);
    }
    offsetDocObj.writeInt((int)documentObj.getFilePointer());
    sortedDimMembers.push(dimRows.getMembers()[levelDefs.length - 1]);
    writeDimensionRow(dimRows,keyDataType,attributesDataType);
    obj=sortedDimensionSet.pop();
    currentIndex++;
  }
  validateDimensionMembers(sortedDimMembers);
  DiskIndex[] diskIndex=new DiskIndex[indexKeyLists.length];
  for (int i=0; i < indexKeyLists.length; i++) {
    diskIndex[i]=DiskIndex.createIndex(documentManager,NamingUtil.getLevelIndexDocName(dimensionName,levelDefs[i].getLevelName()),indexKeyLists[i],false);
  }
  levels=new Level[levelDefs.length];
  for (int i=0; i < levels.length; i++) {
    levels[i]=new Level(documentManager,levelDefs[i],keyDataType[i],attributesDataType[i],currentIndex,diskIndex[i]);
    levels[i].setLevelType(levelDefs[i].getTimeType());
  }
  for (int i=0; i < levels.length; i++) {
    this.levelMap.put(levels[i].getName(),levels[i]);
  }
  return currentIndex;
}

Fixed version (ground truth):
/** 
 * @param levelDefs
 * @param keyDataType
 * @param attributesDataType
 * @param sortedDimensionSet
 * @param stopSign
 * @throws IOException
 * @throws BirtException
 */
private int saveHierarchyRows(ILevelDefn[] levelDefs,int[][] keyDataType,int[][] attributesDataType,DiskSortedStack sortedDimensionSet,StopSign stopSign) throws IOException, BirtException {
  DiskSortedStack sortedDimMembers=new DiskSortedStack(Math.min(sortedDimensionSet.size(),Constants.MAX_DIMENSION_LENGTH),true,false,Member.getCreator());
  IDiskArray[] indexKeyLists=new IDiskArray[keyDataType.length];
  for (int i=0; i < indexKeyLists.length; i++) {
    indexKeyLists[i]=new BufferedStructureArray(IndexKey.getCreator(),Math.min(sortedDimensionSet.size(),Constants.MAX_LIST_BUFFER_SIZE));
  }
  Object obj=sortedDimensionSet.pop();
  int currentIndex=0;
  IndexKey indexKey=null;
  while (obj != null) {
    if (stopSign.isStopped())     break;
    DimensionRow dimRows=(DimensionRow)obj;
    Member[] levelMembers=dimRows.getMembers();
    for (int i=0; i < indexKeyLists.length; i++) {
      indexKey=new IndexKey();
      indexKey.setKey(levelMembers[i].getKeyValues());
      indexKey.setOffset(new int[]{(int)documentObj.getFilePointer()});
      indexKey.setDimensionPos(new int[]{currentIndex});
      indexKeyLists[i].add(indexKey);
    }
    offsetDocObj.writeInt((int)documentObj.getFilePointer());
    sortedDimMembers.push(dimRows.getMembers()[levelDefs.length - 1]);
    writeDimensionRow(dimRows,keyDataType,attributesDataType);
    obj=sortedDimensionSet.pop();
    currentIndex++;
  }
  validateDimensionMembers(sortedDimMembers);
  DiskIndex[] diskIndex=new DiskIndex[indexKeyLists.length];
  for (int i=0; i < indexKeyLists.length; i++) {
    diskIndex[i]=DiskIndex.createIndex(documentManager,NamingUtil.getLevelIndexDocName(dimensionName,levelDefs[i].getLevelName()),indexKeyLists[i],false);
  }
  levels=new Level[levelDefs.length];
  for (int i=0; i < levels.length; i++) {
    levels[i]=new Level(documentManager,levelDefs[i],keyDataType[i],attributesDataType[i],currentIndex,diskIndex[i]);
    levels[i].setLevelType(levelDefs[i].getTimeType());
  }
  for (int i=0; i < levels.length; i++) {
    this.levelMap.put(levels[i].getName(),levels[i]);
  }
  return currentIndex;
}