Program: 65965
Project: 65965
Buggy source:
/** 
 * Find the value matcher in cube cursor. Based on sort direction and compared result, decide to move on/back along resultset.
 * @param rs
 * @param levelList
 * @param valueMap
 * @param aggrIndex
 * @return
 */
private boolean findValueMatcher(IAggregationResultSet rs,List levelList,Map valueMap,int aggrIndex){
  if (levelList.isEmpty())   return true;
  int start=0, state=0;
  boolean find=false;
  currentPosition[aggrIndex]=rs.getPosition();
  for (; start < levelList.size(); ) {
    DimLevel level=(DimLevel)levelList.get(start);
    Object value1=valueMap.get(level);
    Object value2=null;
    int index=rs.getLevelIndex(level);
    Object[] keyValues=rs.getLevelKeyValue(index);
    if (keyValues != null)     value2=keyValues[rs.getLevelKeyColCount(index) - 1];
    int sortType=rs.getSortType(index) == IDimensionSortDefn.SORT_DESC ? -1 : 1;
    int direction=sortType * compare(value1,value2) < 0 ? -1 : compare(value1,value2) == 0 ? 0 : 1;
    if (direction < 0 && currentPosition[aggrIndex] > 0 && (state == 0 || state == direction)) {
      state=direction;
      try {
        rs.seek(--currentPosition[aggrIndex]);
      }
 catch (      IOException e) {
        find=false;
      }
      start=0;
      continue;
    }
 else     if (direction > 0 && currentPosition[aggrIndex] < rs.length() - 1 && (state == 0 || state == direction)) {
      state=direction;
      try {
        rs.seek(++currentPosition[aggrIndex]);
      }
 catch (      IOException e) {
        find=false;
      }
      start=0;
      continue;
    }
 else     if (direction == 0) {
      if (start == levelList.size() - 1) {
        find=true;
        break;
      }
 else {
        start++;
        continue;
      }
    }
 else     if (currentPosition[aggrIndex] < 0 || currentPosition[aggrIndex] >= rs.length()) {
      return false;
    }
 else     return false;
  }
  return find;
}

Fixed version (ground truth):
/** 
 * Find the value matcher in cube cursor. Based on sort direction and compared result, decide to move on/back along resultset.
 * @param rs
 * @param levelList
 * @param valueMap
 * @param aggrIndex
 * @return
 */
private boolean findValueMatcher(IAggregationResultSet rs,List levelList,Map valueMap,int aggrIndex){
  if (levelList.isEmpty())   return true;
  int start=0, state=0;
  boolean find=false;
  currentPosition[aggrIndex]=rs.getPosition();
  for (; start < levelList.size(); ) {
    DimLevel level=(DimLevel)levelList.get(start);
    Object value1=valueMap.get(level);
    Object value2=null;
    int index=rs.getLevelIndex(level);
    Object[] keyValues=rs.getLevelKeyValue(index);
    if (keyValues != null)     value2=keyValues[rs.getLevelKeyColCount(index) - 1];
    int sortType=rs.getSortType(index) == IDimensionSortDefn.SORT_DESC ? -1 : 1;
    int compare=compare(value1,value2);
    int direction=sortType * compare < 0 ? -1 : compare == 0 ? 0 : 1;
    if (direction < 0 && currentPosition[aggrIndex] > 0 && (state == 0 || state == direction)) {
      state=direction;
      try {
        rs.seek(--currentPosition[aggrIndex]);
      }
 catch (      IOException e) {
        find=false;
      }
      start=0;
      continue;
    }
 else     if (direction > 0 && currentPosition[aggrIndex] < rs.length() - 1 && (state == 0 || state == direction)) {
      state=direction;
      try {
        rs.seek(++currentPosition[aggrIndex]);
      }
 catch (      IOException e) {
        find=false;
      }
      start=0;
      continue;
    }
 else     if (direction == 0) {
      if (start == levelList.size() - 1) {
        find=true;
        break;
      }
 else {
        start++;
        continue;
      }
    }
 else     if (currentPosition[aggrIndex] < 0 || currentPosition[aggrIndex] >= rs.length()) {
      return false;
    }
 else     return false;
  }
  return find;
}