Program: 66958
Project: 66958
Buggy source:
/** 
 * aggregation values to disk arrays for the specified AggrSortDefinitions who share the same target aggregation result set.
 * @param base
 * @param targetResultSet
 * @param sortIndex
 * @param targetSorts
 * @param keyDiskArrays
 * @throws IOException
 */
private static void populateAggrKeysForTargetResultSet(IAggregationResultSet base,IAggregationResultSet targetResultSet,int[] sortIndex,ITargetSort[] targetSorts,IDiskArray[] keyDiskArrays) throws IOException {
  AggrSortDefinition sortDefinition=(AggrSortDefinition)targetSorts[sortIndex[0]];
  DimLevel targetLevel=sortDefinition.getTargetLevel();
  final AggregationDefinition aggrDefinition=targetResultSet.getAggregationDefinition();
  if (aggrDefinition == null || aggrDefinition.getAggregationFunctions() == null) {
    int levelIndex=targetResultSet.getLevelIndex(targetLevel);
    for (int i=0; i < base.length(); i++) {
      base.seek(i);
      Object key=base.getLevelKeyValue(levelIndex)[0];
      for (int j=0; j < sortIndex.length; j++) {
        keyDiskArrays[sortIndex[j]].add(key);
      }
    }
    return;
  }
  DimLevel[] axisQualifierLevel=sortDefinition.getAxisQualifierLevel();
  int[] levelIndex=new int[axisQualifierLevel.length];
  for (int i=0; i < levelIndex.length; i++) {
    levelIndex[i]=targetResultSet.getLevelIndex(axisQualifierLevel[i]);
  }
  Object[] axisQualifierValue=sortDefinition.getAxisQualifierValue();
  int[] aggrIndex=new int[sortIndex.length];
  for (int i=0; i < sortIndex.length; i++) {
    AggrSortDefinition sortDefn=(AggrSortDefinition)targetSorts[sortIndex[i]];
    aggrIndex[i]=targetResultSet.getAggregationIndex(sortDefn.getAggrName());
  }
  int indexInBase=base.getLevelIndex(targetLevel);
  CompareIndex compareIndex=getCompareIndex(base,targetResultSet,indexInBase);
  int baseRowIndex=0;
  for (int i=0; i < targetResultSet.length(); i++) {
    targetResultSet.seek(i);
    Object[] values=new Object[levelIndex.length];
    for (int j=0; j < levelIndex.length; j++) {
      values[j]=targetResultSet.getLevelKeyValue(levelIndex[j])[0];
    }
    if (CompareUtil.compare(values,axisQualifierValue) == 0) {
      IAggregationResultRow targetRow=targetResultSet.getCurrentRow();
      boolean found=false;
      while (baseRowIndex < base.length()) {
        base.seek(baseRowIndex);
        IAggregationResultRow baseRow=base.getCurrentRow();
        if (shareLevelKey(baseRow,targetRow,compareIndex)) {
          for (int j=0; j < sortIndex.length; j++) {
            keyDiskArrays[sortIndex[j]].add(targetRow.getAggregationValues()[aggrIndex[j]]);
          }
          baseRowIndex++;
          found=true;
        }
 else         if (!found) {
          fillNullValues(sortIndex,keyDiskArrays);
          baseRowIndex++;
        }
 else {
          break;
        }
      }
    }
  }
  for (; baseRowIndex < base.length(); baseRowIndex++) {
    fillNullValues(sortIndex,keyDiskArrays);
  }
}

Fixed version (ground truth):
/** 
 * aggregation values to disk arrays for the specified AggrSortDefinitions who share the same target aggregation result set.
 * @param base
 * @param targetResultSet
 * @param sortIndex
 * @param targetSorts
 * @param keyDiskArrays
 * @throws IOException
 */
private static void populateAggrKeysForTargetResultSet(IAggregationResultSet base,IAggregationResultSet targetResultSet,int[] sortIndex,ITargetSort[] targetSorts,IDiskArray[] keyDiskArrays) throws IOException {
  AggrSortDefinition sortDefinition=(AggrSortDefinition)targetSorts[sortIndex[0]];
  DimLevel targetLevel=sortDefinition.getTargetLevel();
  final AggregationDefinition aggrDefinition=targetResultSet.getAggregationDefinition();
  if (aggrDefinition == null || aggrDefinition.getAggregationFunctions() == null) {
    int levelIndex=targetResultSet.getLevelIndex(targetLevel);
    for (int i=0; i < base.length(); i++) {
      base.seek(i);
      Object key=base.getLevelKeyValue(levelIndex)[0];
      for (int j=0; j < sortIndex.length; j++) {
        keyDiskArrays[sortIndex[j]].add(key);
      }
    }
    return;
  }
  DimLevel[] axisQualifierLevel=sortDefinition.getAxisQualifierLevel();
  int[] levelIndex=new int[axisQualifierLevel.length];
  for (int i=0; i < levelIndex.length; i++) {
    levelIndex[i]=targetResultSet.getLevelIndex(axisQualifierLevel[i]);
  }
  Object[] axisQualifierValue=sortDefinition.getAxisQualifierValue();
  int[] aggrIndex=new int[sortIndex.length];
  for (int i=0; i < sortIndex.length; i++) {
    AggrSortDefinition sortDefn=(AggrSortDefinition)targetSorts[sortIndex[i]];
    aggrIndex[i]=targetResultSet.getAggregationIndex(sortDefn.getAggrName());
  }
  int indexInBase=base.getLevelIndex(targetLevel);
  CompareIndex compareIndex=getCompareIndex(base,targetResultSet,indexInBase);
  int baseRowIndex=0;
  for (int i=0; i < targetResultSet.length(); i++) {
    targetResultSet.seek(i);
    Object[] values=new Object[levelIndex.length];
    for (int j=0; j < levelIndex.length; j++) {
      if (levelIndex[j] == -1)       values[j]=axisQualifierValue[j];
 else       values[j]=targetResultSet.getLevelKeyValue(levelIndex[j])[0];
    }
    if (CompareUtil.compare(values,axisQualifierValue) == 0) {
      IAggregationResultRow targetRow=targetResultSet.getCurrentRow();
      boolean found=false;
      while (baseRowIndex < base.length()) {
        base.seek(baseRowIndex);
        IAggregationResultRow baseRow=base.getCurrentRow();
        if (shareLevelKey(baseRow,targetRow,compareIndex)) {
          for (int j=0; j < sortIndex.length; j++) {
            keyDiskArrays[sortIndex[j]].add(targetRow.getAggregationValues()[aggrIndex[j]]);
          }
          baseRowIndex++;
          found=true;
        }
 else         if (!found) {
          fillNullValues(sortIndex,keyDiskArrays);
          baseRowIndex++;
        }
 else {
          break;
        }
      }
    }
  }
  for (; baseRowIndex < base.length(); baseRowIndex++) {
    fillNullValues(sortIndex,keyDiskArrays);
  }
}