Program: 73775
Project: 73775
Buggy source:
/** 
 * Internally walks through the resultset and computes the group breaks cached for subsequent use
 * @param bGrouped Indicates if the resultset contains the group key
 * @return Row indexes containing changing group key values
 */
private int[] findGroupBreaks(List resultSet,GroupKey groupKey,SeriesGrouping seriesGrouping){
  if (groupKey == null || groupKey.getKey() == null) {
    return NO_GROUP_BREAKS;
  }
  boolean groupingEnabled=false;
  if (seriesGrouping != null && seriesGrouping.isEnabled()) {
    groupingEnabled=true;
  }
  GroupKey newGroupKey=groupKey;
  if (groupingEnabled && groupKey.getDirection() == null) {
    newGroupKey=new GroupKey(groupKey.getKey(),SortOption.ASCENDING_LITERAL);
    newGroupKey.setKeyIndex(groupKey.getKeyIndex());
  }
  Collections.sort(resultSet,new TupleComparator(new GroupKey[]{newGroupKey}));
  final int iColumnIndex=newGroupKey.getKeyIndex();
  final ArrayList alBreaks=new ArrayList(8);
  boolean bFirst=true;
  Object oValue, oPreviousValue=null;
  int iRowIndex=0;
  if (groupingEnabled) {
    resetGroupedData(resultSet,iColumnIndex,seriesGrouping);
    final Iterator it=resultSet.iterator();
    int intervalCount=0;
    int lastGroupIndex=0;
    double groupInterval=seriesGrouping.getGroupingInterval();
    while (it.hasNext()) {
      oValue=((Object[])it.next())[iColumnIndex];
      iRowIndex++;
      if (bFirst) {
        bFirst=false;
        oPreviousValue=oValue;
        if (seriesGrouping.getGroupType() == DataType.NUMERIC_LITERAL) {
          lastGroupIndex=(int)Math.floor(Math.abs((((Number)oValue).doubleValue() - BASE_START_INTERVAL_VALUE) / groupInterval));
        }
        continue;
      }
      if (compareObjects(oPreviousValue,oValue,seriesGrouping) != 0) {
        if (seriesGrouping.getGroupType() == DataType.NUMERIC_LITERAL) {
          if (groupInterval == 0) {
            alBreaks.add(new Integer(iRowIndex - 1));
          }
 else {
            int groupIndex=(int)Math.floor(Math.abs((((Number)oValue).doubleValue() - BASE_START_INTERVAL_VALUE) / groupInterval));
            if (lastGroupIndex != groupIndex) {
              alBreaks.add(new Integer(iRowIndex - 1));
            }
            lastGroupIndex=groupIndex;
          }
        }
 else         if (seriesGrouping.getGroupType() == DataType.DATE_TIME_LITERAL) {
          int cunit=GroupingUtil.groupingUnit2CDateUnit(seriesGrouping.getGroupingUnit());
          double diff=CDateTime.computeDifference((CDateTime)oValue,(CDateTime)oPreviousValue,cunit,true);
          if (diff != 0) {
            int groupingInterval=(int)seriesGrouping.getGroupingInterval();
            if (groupingInterval == 0) {
              alBreaks.add(new Integer(iRowIndex - 1));
            }
 else {
              if ((int)Math.floor(Math.abs(diff / groupingInterval)) > 0) {
                alBreaks.add(new Integer(iRowIndex - 1));
              }
            }
          }
        }
 else {
          if (seriesGrouping.getGroupingUnit() == GroupingUnitType.STRING_PREFIX_LITERAL) {
            alBreaks.add(new Integer(iRowIndex - 1));
          }
 else {
            if (intervalCount == (int)seriesGrouping.getGroupingInterval()) {
              alBreaks.add(new Integer(iRowIndex - 1));
              intervalCount=0;
            }
 else {
              intervalCount++;
            }
          }
        }
      }
      oPreviousValue=oValue;
    }
  }
 else {
    final Iterator it=resultSet.iterator();
    while (it.hasNext()) {
      oValue=((Object[])it.next())[iColumnIndex];
      iRowIndex++;
      if (bFirst) {
        bFirst=false;
        oPreviousValue=oValue;
        continue;
      }
      if (compareObjects(oPreviousValue,oValue) != 0) {
        alBreaks.add(new Integer(iRowIndex - 1));
      }
      oPreviousValue=oValue;
    }
  }
  final int[] ia=new int[alBreaks.size()];
  for (int i=0; i < alBreaks.size(); i++) {
    ia[i]=((Integer)alBreaks.get(i)).intValue();
  }
  return ia;
}

Fixed version (ground truth):
/** 
 * Internally walks through the resultset and computes the group breaks cached for subsequent use
 * @param bGrouped Indicates if the resultset contains the group key
 * @return Row indexes containing changing group key values
 */
private int[] findGroupBreaks(List resultSet,GroupKey groupKey,SeriesGrouping seriesGrouping){
  if (groupKey == null || groupKey.getKey() == null) {
    return NO_GROUP_BREAKS;
  }
  boolean groupingEnabled=false;
  if (seriesGrouping != null && seriesGrouping.isSetGroupType()) {
    groupingEnabled=true;
  }
  GroupKey newGroupKey=groupKey;
  if (groupingEnabled && groupKey.getDirection() == null) {
    newGroupKey=new GroupKey(groupKey.getKey(),SortOption.ASCENDING_LITERAL);
    newGroupKey.setKeyIndex(groupKey.getKeyIndex());
  }
  Collections.sort(resultSet,new TupleComparator(new GroupKey[]{newGroupKey}));
  final int iColumnIndex=newGroupKey.getKeyIndex();
  final ArrayList alBreaks=new ArrayList(8);
  boolean bFirst=true;
  Object oValue, oPreviousValue=null;
  int iRowIndex=0;
  if (groupingEnabled) {
    resetGroupedData(resultSet,iColumnIndex,seriesGrouping);
    final Iterator it=resultSet.iterator();
    int intervalCount=0;
    int lastGroupIndex=0;
    double groupInterval=seriesGrouping.getGroupingInterval();
    while (it.hasNext()) {
      oValue=((Object[])it.next())[iColumnIndex];
      iRowIndex++;
      if (bFirst) {
        bFirst=false;
        oPreviousValue=oValue;
        if (seriesGrouping.getGroupType() == DataType.NUMERIC_LITERAL) {
          lastGroupIndex=(int)Math.floor(Math.abs((((Number)oValue).doubleValue() - BASE_START_INTERVAL_VALUE) / groupInterval));
        }
        continue;
      }
      if (compareObjects(oPreviousValue,oValue,seriesGrouping) != 0) {
        if (seriesGrouping.getGroupType() == DataType.NUMERIC_LITERAL) {
          if (groupInterval == 0) {
            alBreaks.add(new Integer(iRowIndex - 1));
          }
 else {
            int groupIndex=(int)Math.floor(Math.abs((((Number)oValue).doubleValue() - BASE_START_INTERVAL_VALUE) / groupInterval));
            if (lastGroupIndex != groupIndex) {
              alBreaks.add(new Integer(iRowIndex - 1));
            }
            lastGroupIndex=groupIndex;
          }
        }
 else         if (seriesGrouping.getGroupType() == DataType.DATE_TIME_LITERAL) {
          int cunit=GroupingUtil.groupingUnit2CDateUnit(seriesGrouping.getGroupingUnit());
          double diff=CDateTime.computeDifference((CDateTime)oValue,(CDateTime)oPreviousValue,cunit,true);
          if (diff != 0) {
            int groupingInterval=(int)seriesGrouping.getGroupingInterval();
            if (groupingInterval == 0) {
              alBreaks.add(new Integer(iRowIndex - 1));
            }
 else {
              if ((int)Math.floor(Math.abs(diff / groupingInterval)) > 0) {
                alBreaks.add(new Integer(iRowIndex - 1));
              }
            }
          }
        }
 else {
          if (seriesGrouping.getGroupingUnit() == GroupingUnitType.STRING_PREFIX_LITERAL) {
            alBreaks.add(new Integer(iRowIndex - 1));
          }
 else {
            if (intervalCount == (int)seriesGrouping.getGroupingInterval()) {
              alBreaks.add(new Integer(iRowIndex - 1));
              intervalCount=0;
            }
 else {
              intervalCount++;
            }
          }
        }
      }
      oPreviousValue=oValue;
    }
  }
 else {
    final Iterator it=resultSet.iterator();
    while (it.hasNext()) {
      oValue=((Object[])it.next())[iColumnIndex];
      iRowIndex++;
      if (bFirst) {
        bFirst=false;
        oPreviousValue=oValue;
        continue;
      }
      if (compareObjects(oPreviousValue,oValue) != 0) {
        alBreaks.add(new Integer(iRowIndex - 1));
      }
      oPreviousValue=oValue;
    }
  }
  final int[] ia=new int[alBreaks.size()];
  for (int i=0; i < alBreaks.size(); i++) {
    ia[i]=((Integer)alBreaks.get(i)).intValue();
  }
  return ia;
}