Program: 75699
Project: 75699
Buggy source:
/** 
 * @param factTableName
 * @param iterator
 * @param dimensions
 * @param measureColumnName
 * @param stopSign
 * @return
 * @throws BirtException
 * @throws IOException
 */
public FactTable saveFactTable(String factTableName,IDatasetIterator iterator,Dimension[] dimensions,String[] measureColumnName,StopSign stopSign) throws BirtException, IOException {
  String[][] keyColumnNames=getKeyColNames(dimensions);
  DiskSortedStack sortedFactTableRows=getSortedFactTableRows(iterator,keyColumnNames,measureColumnName,stopSign);
  int segmentCount=getSegmentCount(sortedFactTableRows.size());
  DimensionInfo[] dimensionInfo=getDimensionInfo(dimensions);
  MeasureInfo[] measureInfo=getMeasureInfo(iterator,measureColumnName);
  saveFactTableMetadata(factTableName,dimensionInfo,measureInfo,segmentCount);
  DimensionDivision[] subDimensions=calculateDimensionDivision(getDimensionMemberCount(dimensions),segmentCount);
  DimensionPositionSeeker[] dimensionSeekers=new DimensionPositionSeeker[dimensions.length];
  for (int i=0; i < dimensionSeekers.length; i++) {
    dimensionSeekers[i]=new DimensionPositionSeeker(getDimCombinatedKey(dimensions[i].getAllRows()));
  }
  FactTableRow currentRow=null;
  FactTableRow lastRow=null;
  int[] dimensionPosition=new int[dimensions.length];
  DocumentObjectCache documentObjectManager=new DocumentObjectCache(documentManager);
  CombinedPositionContructor combinedPositionCalculator=new CombinedPositionContructor(subDimensions);
  FTSUNameSaveHelper helper=new FTSUNameSaveHelper(documentManager,factTableName);
  Object popObject=sortedFactTableRows.pop();
  while (popObject != null && !stopSign.isStopped()) {
    currentRow=(FactTableRow)popObject;
    if (lastRow != null && currentRow.equals(lastRow)) {
      throw new DataException(ResourceConstants.FACTTABLE_ROW_NOT_DISTINCT,currentRow.toString());
    }
    for (int i=0; i < dimensionPosition.length; i++) {
      dimensionPosition[i]=dimensionSeekers[i].find(currentRow.getDimensionKeys()[i]);
      if (dimensionPosition[i] < 0) {
        String[] args=new String[2];
        args[0]=currentRow.toString();
        args[1]=dimensions[i].getName();
        throw new DataException(ResourceConstants.INVALID_DIMENSIONPOSITION_OF_FACTTABLEROW,args);
      }
    }
    int[] subDimensionIndex=getSubDimensionIndex(dimensionPosition,subDimensions);
    String FTSUDocName=FTSUDocumentObjectNamingUtil.getDocumentObjectName(NamingUtil.getFactTableName(factTableName),subDimensionIndex);
    helper.add(FTSUDocName);
    IDocumentObject documentObject=documentObjectManager.getIDocumentObject(FTSUDocName);
    documentObject.writeBytes(new Bytes(combinedPositionCalculator.calculateCombinedPosition(subDimensionIndex,dimensionPosition).toByteArray()));
    for (int i=0; i < measureInfo.length; i++) {
      DocumentObjectUtil.writeValue(documentObject,measureInfo[i].dataType,currentRow.getMeasures()[i]);
    }
    popObject=sortedFactTableRows.pop();
    lastRow=currentRow;
  }
  helper.save();
  documentObjectManager.closeAll();
  documentManager.flush();
  return new FactTable(factTableName,documentManager,dimensionInfo,measureInfo,segmentCount,subDimensions);
}

Fixed version (ground truth):
/** 
 * @param factTableName
 * @param iterator
 * @param dimensions
 * @param measureColumnName
 * @param stopSign
 * @return
 * @throws BirtException
 * @throws IOException
 */
public FactTable saveFactTable(String factTableName,String[][] keyColumnNames,IDatasetIterator iterator,Dimension[] dimensions,String[] measureColumnName,StopSign stopSign) throws BirtException, IOException {
  DiskSortedStack sortedFactTableRows=getSortedFactTableRows(iterator,keyColumnNames,measureColumnName,stopSign);
  int segmentCount=getSegmentCount(sortedFactTableRows.size());
  DimensionInfo[] dimensionInfo=getDimensionInfo(dimensions);
  MeasureInfo[] measureInfo=getMeasureInfo(iterator,measureColumnName);
  saveFactTableMetadata(factTableName,dimensionInfo,measureInfo,segmentCount);
  DimensionDivision[] subDimensions=calculateDimensionDivision(getDimensionMemberCount(dimensions),segmentCount);
  DimensionPositionSeeker[] dimensionSeekers=new DimensionPositionSeeker[dimensions.length];
  for (int i=0; i < dimensionSeekers.length; i++) {
    dimensionSeekers[i]=new DimensionPositionSeeker(getDimCombinatedKey(dimensions[i].getAllRows()));
  }
  FactTableRow currentRow=null;
  FactTableRow lastRow=null;
  int[] dimensionPosition=new int[dimensions.length];
  DocumentObjectCache documentObjectManager=new DocumentObjectCache(documentManager);
  CombinedPositionContructor combinedPositionCalculator=new CombinedPositionContructor(subDimensions);
  FTSUNameSaveHelper helper=new FTSUNameSaveHelper(documentManager,factTableName);
  Object popObject=sortedFactTableRows.pop();
  while (popObject != null && !stopSign.isStopped()) {
    currentRow=(FactTableRow)popObject;
    if (lastRow != null && currentRow.equals(lastRow)) {
      throw new DataException(ResourceConstants.FACTTABLE_ROW_NOT_DISTINCT,currentRow.toString());
    }
    for (int i=0; i < dimensionPosition.length; i++) {
      dimensionPosition[i]=dimensionSeekers[i].find(currentRow.getDimensionKeys()[i]);
      if (dimensionPosition[i] < 0) {
        String[] args=new String[2];
        args[0]=currentRow.toString();
        args[1]=dimensions[i].getName();
        throw new DataException(ResourceConstants.INVALID_DIMENSIONPOSITION_OF_FACTTABLEROW,args);
      }
    }
    int[] subDimensionIndex=getSubDimensionIndex(dimensionPosition,subDimensions);
    String FTSUDocName=FTSUDocumentObjectNamingUtil.getDocumentObjectName(NamingUtil.getFactTableName(factTableName),subDimensionIndex);
    helper.add(FTSUDocName);
    IDocumentObject documentObject=documentObjectManager.getIDocumentObject(FTSUDocName);
    documentObject.writeBytes(new Bytes(combinedPositionCalculator.calculateCombinedPosition(subDimensionIndex,dimensionPosition).toByteArray()));
    for (int i=0; i < measureInfo.length; i++) {
      DocumentObjectUtil.writeValue(documentObject,measureInfo[i].dataType,currentRow.getMeasures()[i]);
    }
    popObject=sortedFactTableRows.pop();
    lastRow=currentRow;
  }
  helper.save();
  documentObjectManager.closeAll();
  documentManager.flush();
  return new FactTable(factTableName,documentManager,dimensionInfo,measureInfo,segmentCount,subDimensions);
}