Program: 64950
Project: 64950
Buggy source:
TimeFunctionCalculator(AggregationDefinition aggr,DimColumn[] parameterColNames,IDataSet4Aggregation.MetaInfo metaInfo,ICubeDimensionReader cubeDimensionReader,long memoryCacheSize) throws DataException, IOException {
  AggregationFunctionDefinition[] timeFunction=aggr.getAggregationTimeFunctions();
  if (timeFunction == null) {
    existTimeFunction=false;
    return;
  }
  existTimeFunction=true;
  tDimName=timeFunction[0].getTimeFunction().getTimeDimension();
  timeDimension=cubeDimensionReader.getDimension(tDimName);
  periodFunction=createTimeFunction(timeFunction);
  periodFunctionResultCache=new Map[periodFunction.length];
  for (int i=0; i < periodFunctionResultCache.length; i++) {
    periodFunctionResultCache[i]=new HashMap<TimeMember,List<TimeMember>>();
  }
  timeDimensionIndex=cubeDimensionReader.getDimensionIndex(tDimName);
  lowestTimeLevel=getLowestTimeLevel(aggr);
  firstTimeLevel=getFirstTimeLevel(aggr);
  existReferenceDate=false;
  existLastDate=false;
  referenceDate=new Date[timeFunction.length];
  for (int i=0; i < timeFunction.length; i++) {
    if (timeFunction[i].getTimeFunction().getReferenceDate() != null)     referenceDate[i]=timeFunction[i].getTimeFunction().getReferenceDate().getDate();
    if (referenceDate[i] != null) {
      existReferenceDate=true;
      int levelIndex1=cubeDimensionReader.getlowestLevelIndex(tDimName) - 1;
      int levelIndex2=cubeDimensionReader.getLevelIndex(tDimName,aggr.getLevels()[lowestTimeLevel].getLevelName());
      if (levelIndex1 == levelIndex2) {
        this.avoidExtraSort=true;
      }
    }
 else {
      existLastDate=true;
    }
  }
  if (existReferenceDate) {
    endLevelIndex=cubeDimensionReader.getlowestLevelIndex(tDimName) - 1;
  }
 else {
    endLevelIndex=cubeDimensionReader.getLevelIndex(tDimName,aggr.getLevels()[lowestTimeLevel].getLevelName());
  }
  orignalLevelCount=aggr.getLevels().length;
  newMemberSize=aggr.getLevels().length - (lowestTimeLevel - firstTimeLevel + 1) + (endLevelIndex + 1);
  sortType=getSortType(aggr,cubeDimensionReader);
  Comparator comparator=new Row4AggregationComparator(sortType);
  int levelCount=0;
  if (aggr.getLevels() == null)   levelCount=0;
 else   levelCount=aggr.getLevels().length;
  int levelSize=0;
  if (levelCount != 0) {
    levelSize=getLevelSize(metaInfo,aggr.getLevels());
  }
  int measureSize=0;
  if (aggregationFunction != null && aggregationFunction.length > 0) {
    measureSize=aggregationFunction.length * 64;
  }
  int rowSize=16 + (4 + (levelSize + measureSize) - 1) / 8 * 8;
  int bufferSize=(int)(memoryCacheSize / rowSize);
  if (bufferSize < 100)   bufferSize=100;
  if (this.existReferenceDate) {
    if (!this.avoidExtraSort) {
      sortedFactRows=new DiskSortedStack(bufferSize,false,comparator,Row4Aggregation.getCreator());
      if (memoryCacheSize == 0) {
        sortedFactRows.setUseMemoryOnly(true);
      }
    }
 else {
      factRows=new BufferedStructureArray(Row4Aggregation.getCreator(),bufferSize);
      if (memoryCacheSize == 0) {
        factRows.setUseMemoryOnly(true);
      }
      factRowPostion=0;
    }
  }
  if (this.existLastDate) {
    factRows=new BufferedStructureArray(Row4Aggregation.getCreator(),bufferSize);
    if (memoryCacheSize == 0) {
      factRows.setUseMemoryOnly(true);
    }
    factRowPostion=0;
  }
  comparator=new MemberCellIndexComparator(getSortType(aggr,cubeDimensionReader));
  timeMemberFilters=new DiskSortedStack[timeFunction.length];
  for (int i=0; i < timeMemberFilters.length; i++) {
    timeMemberFilters[i]=new DiskSortedStack(bufferSize,false,comparator,MemberCellIndex.getCreator());
    if (memoryCacheSize == 0) {
      timeMemberFilters[i].setUseMemoryOnly(true);
    }
  }
  this.aggregation=aggr;
  this.measureIndexes=new int[timeFunction.length];
  this.parameterColIndex=new int[timeFunction.length];
  this.aggregationFunction=new IAggrFunction[timeFunction.length];
  for (int i=0; i < timeFunction.length; i++) {
    aggregationFunction[i]=AggregationManager.getInstance().getAggregation(timeFunction[i].getFunctionName());
    if (aggregationFunction[i] == null) {
      throw new DataException(DataResourceHandle.getInstance().getMessage(ResourceConstants.UNSUPPORTED_FUNCTION) + timeFunction[i].getFunctionName());
    }
    if (AggregationUtil.needDataField(aggregationFunction[i])) {
      this.parameterColIndex[i]=find(parameterColNames,timeFunction[i].getParaCol());
    }
 else {
      this.parameterColIndex[i]=-1;
    }
    final String measureName=timeFunction[i].getMeasureName();
    this.measureIndexes[i]=metaInfo.getMeasureIndex(measureName);
    if (this.measureIndexes[i] == -1 && measureName != null) {
      throw new DataException(ResourceConstants.MEASURE_NAME_NOT_FOUND,measureName);
    }
  }
  measureInfos=metaInfo.getMeasureInfos();
  facttableRow=new FacttableRow(measureInfos,cubeDimensionReader,metaInfo);
  this.cubeDimensionReader=cubeDimensionReader;
  getLevelType();
}

Fixed version (ground truth):
TimeFunctionCalculator(AggregationDefinition aggr,DimColumn[] parameterColNames,IDataSet4Aggregation.MetaInfo metaInfo,ICubeDimensionReader cubeDimensionReader,long memoryCacheSize) throws DataException, IOException {
  AggregationFunctionDefinition[] timeFunction=aggr.getAggregationTimeFunctions();
  if (timeFunction == null) {
    existTimeFunction=false;
    return;
  }
  existTimeFunction=true;
  tDimName=timeFunction[0].getTimeFunction().getTimeDimension();
  timeDimension=cubeDimensionReader.getDimension(tDimName);
  periodFunction=createTimeFunction(timeFunction);
  periodFunctionResultCache=new Map[periodFunction.length];
  for (int i=0; i < periodFunctionResultCache.length; i++) {
    periodFunctionResultCache[i]=new HashMap<TimeMember,List<TimeMember>>();
  }
  timeDimensionIndex=cubeDimensionReader.getDimensionIndex(tDimName);
  lowestTimeLevel=getLowestTimeLevel(aggr);
  firstTimeLevel=getFirstTimeLevel(aggr);
  existReferenceDate=false;
  existLastDate=false;
  referenceDate=new Date[timeFunction.length];
  for (int i=0; i < timeFunction.length; i++) {
    if (timeFunction[i].getTimeFunction().getReferenceDate() != null)     referenceDate[i]=timeFunction[i].getTimeFunction().getReferenceDate().getDate();
    if (referenceDate[i] != null) {
      existReferenceDate=true;
      int levelIndex1=cubeDimensionReader.getlowestLevelIndex(tDimName) - 1;
      int levelIndex2=cubeDimensionReader.getLevelIndex(tDimName,aggr.getLevels()[lowestTimeLevel].getLevelName());
      if (levelIndex1 == levelIndex2) {
        this.avoidExtraSort=true;
      }
    }
 else {
      existLastDate=true;
    }
  }
  if (existReferenceDate) {
    if (cubeDimensionReader.getlowestLevelIndex(tDimName) == 0)     endLevelIndex=0;
 else     endLevelIndex=cubeDimensionReader.getlowestLevelIndex(tDimName) - 1;
  }
 else {
    endLevelIndex=cubeDimensionReader.getLevelIndex(tDimName,aggr.getLevels()[lowestTimeLevel].getLevelName());
  }
  orignalLevelCount=aggr.getLevels().length;
  newMemberSize=aggr.getLevels().length - (lowestTimeLevel - firstTimeLevel + 1) + (endLevelIndex + 1);
  sortType=getSortType(aggr,cubeDimensionReader);
  Comparator comparator=new Row4AggregationComparator(sortType);
  int levelCount=0;
  if (aggr.getLevels() == null)   levelCount=0;
 else   levelCount=aggr.getLevels().length;
  int levelSize=0;
  if (levelCount != 0) {
    levelSize=getLevelSize(metaInfo,aggr.getLevels());
  }
  int measureSize=0;
  if (aggregationFunction != null && aggregationFunction.length > 0) {
    measureSize=aggregationFunction.length * 64;
  }
  int rowSize=16 + (4 + (levelSize + measureSize) - 1) / 8 * 8;
  int bufferSize=(int)(memoryCacheSize / rowSize);
  if (bufferSize < 100)   bufferSize=100;
  if (this.existReferenceDate) {
    if (!this.avoidExtraSort) {
      sortedFactRows=new DiskSortedStack(bufferSize,false,comparator,Row4Aggregation.getCreator());
      if (memoryCacheSize == 0) {
        sortedFactRows.setUseMemoryOnly(true);
      }
    }
 else {
      factRows=new BufferedStructureArray(Row4Aggregation.getCreator(),bufferSize);
      if (memoryCacheSize == 0) {
        factRows.setUseMemoryOnly(true);
      }
      factRowPostion=0;
    }
  }
  if (this.existLastDate) {
    factRows=new BufferedStructureArray(Row4Aggregation.getCreator(),bufferSize);
    if (memoryCacheSize == 0) {
      factRows.setUseMemoryOnly(true);
    }
    factRowPostion=0;
  }
  comparator=new MemberCellIndexComparator(getSortType(aggr,cubeDimensionReader));
  timeMemberFilters=new DiskSortedStack[timeFunction.length];
  for (int i=0; i < timeMemberFilters.length; i++) {
    timeMemberFilters[i]=new DiskSortedStack(bufferSize,false,comparator,MemberCellIndex.getCreator());
    if (memoryCacheSize == 0) {
      timeMemberFilters[i].setUseMemoryOnly(true);
    }
  }
  this.aggregation=aggr;
  this.measureIndexes=new int[timeFunction.length];
  this.parameterColIndex=new int[timeFunction.length];
  this.aggregationFunction=new IAggrFunction[timeFunction.length];
  for (int i=0; i < timeFunction.length; i++) {
    aggregationFunction[i]=AggregationManager.getInstance().getAggregation(timeFunction[i].getFunctionName());
    if (aggregationFunction[i] == null) {
      throw new DataException(DataResourceHandle.getInstance().getMessage(ResourceConstants.UNSUPPORTED_FUNCTION) + timeFunction[i].getFunctionName());
    }
    if (AggregationUtil.needDataField(aggregationFunction[i])) {
      this.parameterColIndex[i]=find(parameterColNames,timeFunction[i].getParaCol());
    }
 else {
      this.parameterColIndex[i]=-1;
    }
    final String measureName=timeFunction[i].getMeasureName();
    this.measureIndexes[i]=metaInfo.getMeasureIndex(measureName);
    if (this.measureIndexes[i] == -1 && measureName != null) {
      throw new DataException(ResourceConstants.MEASURE_NAME_NOT_FOUND,measureName);
    }
  }
  measureInfos=metaInfo.getMeasureInfos();
  facttableRow=new FacttableRow(measureInfos,cubeDimensionReader,metaInfo);
  this.cubeDimensionReader=cubeDimensionReader;
  getLevelType();
}