Program: 75696
Project: 75696
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;
  for (; start < levelList.size(); ) {
    DimLevel level=(DimLevel)levelList.get(start);
    Object value1=valueMap.get(level);
    Object value2=rs.getLevelKeyValue(rs.getLevelIndex(level))[0];
    int sortType=rs.getSortType(rs.getLevelIndex(level)) == IDimensionSortDefn.SORT_DESC ? -1 : 1;
    int direction=sortType * ((Comparable)value1).compareTo(value2) < 0 ? -1 : ((Comparable)value1).compareTo(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;
  for (; start < levelList.size(); ) {
    DimLevel level=(DimLevel)levelList.get(start);
    Object value1=valueMap.get(level);
    Object value2=rs.getLevelKeyValue(rs.getLevelIndex(level))[rs.getLevelKeyColCount(rs.getLevelIndex(level)) - 1];
    int sortType=rs.getSortType(rs.getLevelIndex(level)) == IDimensionSortDefn.SORT_DESC ? -1 : 1;
    int direction=sortType * ((Comparable)value1).compareTo(value2) < 0 ? -1 : ((Comparable)value1).compareTo(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;
}