Program: 67382
Project: 67382
Buggy source:
/** 
 * @throws IOException 
 * @throws DataException 
 */
private void prepareSortedStacks() throws DataException, IOException {
  allSortedFactRows=new ArrayList();
  int levelSize=0;
  int measureSize=0;
  while (true) {
    int maxLevelCount=0;
    int aggregationIndex=-1;
    int[] levelSortType=null;
    for (int i=0; i < aggregationCalculators.length; i++) {
      if (sortedFactRows[i] == null && ((aggregationCalculators[i].aggregation.getLevels() != null && aggregationCalculators[i].aggregation.getLevels().length > maxLevelCount) || aggregationCalculators[i].aggregation.getLevels() == null)) {
        aggregationIndex=i;
        maxLevelCount=levelIndex[i].length;
        levelSortType=aggregationCalculators[i].aggregation.getSortTypes();
      }
    }
    if (aggregationIndex == -1) {
      break;
    }
    if (memoryCacheSize != 0) {
      if (levelSize == 0)       levelSize=getLevelSize(aggregationCalculators[aggregationIndex].aggregation.getLevels());
 else       levelSize+=getArraySize(aggregationCalculators[aggregationIndex].aggregation.getLevels().length);
      if (measureSize == 0)       measureSize=getMeasureSize();
 else       measureSize+=getArraySize(dataSet4Aggregation.getMetaInfo().getMeasureInfos().length);
    }
    Comparator comparator=new Row4AggregationComparator(levelSortType);
    DiskSortedStack diskSortedStack=new DiskSortedStack(100,false,comparator,Row4Aggregation.getCreator());
    if (memoryCacheSize == 0) {
      diskSortedStack.setBufferSize(10000);
      diskSortedStack.setUseMemoryOnly(true);
    }
    DiskSortedStackWrapper diskSortedStackReader=new DiskSortedStackWrapper(diskSortedStack,levelIndex[aggregationIndex]);
    this.allSortedFactRows.add(diskSortedStackReader);
    for (int i=0; i < aggregationCalculators.length; i++) {
      if (sortedFactRows[i] == null && cover(levelIndex[aggregationIndex],levelIndex[i])) {
        sortedFactRows[i]=diskSortedStackReader;
      }
    }
  }
  if (memoryCacheSize > 0) {
    int rowSize=16 + (4 + (levelSize + measureSize) - 1) / 8 * 8;
    int bufferSize=(int)(this.memoryCacheSize / rowSize);
    for (int i=0; i < allSortedFactRows.size(); i++) {
      DiskSortedStackWrapper diskSortedStackReader=(DiskSortedStackWrapper)allSortedFactRows.get(i);
      diskSortedStackReader.getDiskSortedStack().setBufferSize(bufferSize);
    }
  }
}

Fixed version (ground truth):
/** 
 * @throws IOException 
 * @throws DataException 
 */
private void prepareSortedStacks() throws DataException, IOException {
  allSortedFactRows=new ArrayList();
  int levelSize=0;
  int measureSize=0;
  while (true) {
    int maxLevelCount=0;
    int aggregationIndex=-1;
    int[] levelSortType=null;
    for (int i=0; i < aggregationCalculators.length; i++) {
      if (sortedFactRows[i] == null && ((aggregationCalculators[i].aggregation.getLevels() != null && aggregationCalculators[i].aggregation.getLevels().length > maxLevelCount) || aggregationCalculators[i].aggregation.getLevels() == null)) {
        aggregationIndex=i;
        maxLevelCount=levelIndex[i].length;
        levelSortType=aggregationCalculators[i].aggregation.getSortTypes();
      }
    }
    if (aggregationIndex == -1) {
      break;
    }
    if (memoryCacheSize != 0) {
      if (levelSize == 0)       levelSize=getLevelSize(aggregationCalculators[aggregationIndex].aggregation.getLevels());
 else {
        if (aggregationCalculators[aggregationIndex].aggregation.getLevels() != null)         levelSize+=getArraySize(aggregationCalculators[aggregationIndex].aggregation.getLevels().length);
      }
      if (measureSize == 0)       measureSize=getMeasureSize();
 else {
        if (dataSet4Aggregation.getMetaInfo().getMeasureInfos() != null)         measureSize+=getArraySize(dataSet4Aggregation.getMetaInfo().getMeasureInfos().length);
      }
    }
    Comparator comparator=new Row4AggregationComparator(levelSortType);
    DiskSortedStack diskSortedStack=new DiskSortedStack(100,false,comparator,Row4Aggregation.getCreator());
    if (memoryCacheSize == 0) {
      diskSortedStack.setBufferSize(10000);
      diskSortedStack.setUseMemoryOnly(true);
    }
    DiskSortedStackWrapper diskSortedStackReader=new DiskSortedStackWrapper(diskSortedStack,levelIndex[aggregationIndex]);
    this.allSortedFactRows.add(diskSortedStackReader);
    for (int i=0; i < aggregationCalculators.length; i++) {
      if (sortedFactRows[i] == null && cover(levelIndex[aggregationIndex],levelIndex[i])) {
        sortedFactRows[i]=diskSortedStackReader;
      }
    }
  }
  if (memoryCacheSize > 0) {
    int rowSize=16 + (4 + (levelSize + measureSize) - 1) / 8 * 8;
    int bufferSize=(int)(this.memoryCacheSize / rowSize);
    for (int i=0; i < allSortedFactRows.size(); i++) {
      DiskSortedStackWrapper diskSortedStackReader=(DiskSortedStackWrapper)allSortedFactRows.get(i);
      diskSortedStackReader.getDiskSortedStack().setBufferSize(bufferSize);
    }
  }
}