Program: 67473
Project: 67473
Buggy source:
private static Integer binarySearch(Object target,List sortedList,int searchOption) throws DataException {
  int low=0;
  int high=sortedList.size() - 1;
  int mid=(low + high) >> 1;
  while (low <= high) {
    mid=(low + high) >> 1;
    Object midVal=sortedList.get(mid);
    int cmp=ScriptEvalUtil.compare(midVal,target);
    if (cmp < 0)     low=mid + 1;
 else     if (cmp > 0)     high=mid - 1;
 else {
      if (searchOption == IConditionalExpression.OP_EQ || searchOption == IConditionalExpression.OP_GE || searchOption == IConditionalExpression.OP_LE)       return mid;
      break;
    }
  }
  if (low > high) {
    int temp=low;
    low=high;
    high=temp;
    if (high >= sortedList.size())     high=sortedList.size() - 1;
  }
  if (searchOption == IConditionalExpression.OP_EQ) {
    int threshHold=-1;
    for (int i=low; i <= high; i++) {
      if (ScriptEvalUtil.compare(sortedList.get(i),target) == 0) {
        return i;
      }
    }
  }
 else   if (searchOption == IConditionalExpression.OP_GE) {
    for (int i=low; i <= high; i++) {
      if (ScriptEvalUtil.compare(sortedList.get(i),target) >= 0) {
        return i;
      }
    }
  }
 else   if (searchOption == IConditionalExpression.OP_LE) {
    for (int i=high; i >= low; i--) {
      if (ScriptEvalUtil.compare(sortedList.get(i),target) <= 0) {
        return i;
      }
    }
  }
 else   if (searchOption == IConditionalExpression.OP_GT) {
    for (int i=low; i <= high; i++) {
      if (ScriptEvalUtil.compare(sortedList.get(i),target) > 0) {
        return i;
      }
    }
  }
 else   if (searchOption == IConditionalExpression.OP_LT) {
    for (int i=high; i >= low; i--) {
      if (ScriptEvalUtil.compare(sortedList.get(i),target) < 0) {
        return i;
      }
    }
  }
  return -1;
}

Fixed version (ground truth):
private static Integer binarySearch(Object target,List sortedList,int searchOption) throws DataException {
  int low=0;
  int high=sortedList.size() - 1;
  int mid=(low + high) >> 1;
  while (low <= high) {
    mid=(low + high) >> 1;
    Object midVal=sortedList.get(mid);
    int cmp=ScriptEvalUtil.compare(midVal,target);
    if (cmp < 0)     low=mid + 1;
 else     if (cmp > 0)     high=mid - 1;
 else {
      if (searchOption == IConditionalExpression.OP_EQ || searchOption == IConditionalExpression.OP_GE || searchOption == IConditionalExpression.OP_LE)       return mid;
      break;
    }
  }
  if (low > high) {
    int temp=low;
    low=high;
    high=temp;
    if (high >= sortedList.size())     high=sortedList.size() - 1;
  }
  if (searchOption == IConditionalExpression.OP_EQ) {
    int threshHold=-1;
    for (int i=low; i <= high; i++) {
      if (ScriptEvalUtil.compare(sortedList.get(i),target) == 0) {
        return i;
      }
    }
  }
 else   if (searchOption == IConditionalExpression.OP_GE) {
    for (int i=low; i <= high; i++) {
      if (ScriptEvalUtil.compare(sortedList.get(i),target) >= 0) {
        return i;
      }
    }
  }
 else   if (searchOption == IConditionalExpression.OP_LE) {
    for (int i=high; i >= low; i--) {
      if (ScriptEvalUtil.compare(sortedList.get(i),target) <= 0) {
        return i;
      }
    }
  }
 else   if (searchOption == IConditionalExpression.OP_GT) {
    if (high == low)     return high + 1;
    for (int i=low; i <= high; i++) {
      if (ScriptEvalUtil.compare(sortedList.get(i),target) > 0) {
        return i;
      }
    }
  }
 else   if (searchOption == IConditionalExpression.OP_LT) {
    if (high == low)     return high - 1;
    for (int i=high; i >= low; i--) {
      if (ScriptEvalUtil.compare(sortedList.get(i),target) < 0) {
        return i;
      }
    }
  }
  return -1;
}