Program: 70246
Project: 70246
Buggy source:
private void groupDateTime(List resultSet,int iBaseColumnIndex,int[] iaColumnIndexes,int[] iaBreaks,CDateTime ndeBaseReference,long iGroupingInterval,GroupingUnitType groupingUnit,IAggregateFunction[] iafa) throws ChartException {
  final int iOrthogonalSeriesCount=iaColumnIndexes.length;
  int cunit=GroupingUtil.groupingUnit2CDateUnit(groupingUnit);
  int iStartIndex=0, iEndIndex;
  int totalGroupCount=iaBreaks == null ? 1 : (iaBreaks.length + 1);
  int totalRowCount=resultSet.size();
  for (int k=0; k < totalGroupCount; k++) {
    if (k == totalGroupCount - 1) {
      iEndIndex=totalRowCount;
    }
 else {
      iEndIndex=iaBreaks[k];
    }
    CDateTime baseReference=ndeBaseReference;
    if (baseReference == null) {
      Object obj=((Object[])resultSet.get(iStartIndex))[iBaseColumnIndex];
      if (obj instanceof CDateTime) {
        baseReference=(CDateTime)obj;
      }
 else       if (obj instanceof Calendar) {
        baseReference=new CDateTime((Calendar)obj);
      }
 else       if (obj instanceof Date) {
        baseReference=new CDateTime((Date)obj);
      }
 else {
        baseReference=new CDateTime(0);
      }
    }
    baseReference.clearBelow(cunit);
    Object[] oaTuple, oaSummarizedTuple=null;
    int iGroupIndex=0, iLastGroupIndex=0;
    boolean bFirst=true, bGroupBreak=false;
    List trashList=new ArrayList();
    for (int j=iStartIndex; j < iEndIndex; j++) {
      oaTuple=(Object[])resultSet.get(j);
      CDateTime dCurrentValue=null;
      if (oaTuple[iBaseColumnIndex] != null) {
        Object obj=oaTuple[iBaseColumnIndex];
        if (obj instanceof CDateTime) {
          dCurrentValue=(CDateTime)obj;
        }
 else         if (obj instanceof Calendar) {
          dCurrentValue=new CDateTime((Calendar)obj);
        }
 else         if (obj instanceof Date) {
          dCurrentValue=new CDateTime((Date)obj);
        }
 else {
          dCurrentValue=new CDateTime(0);
        }
        dCurrentValue.clearBelow(cunit);
      }
 else {
        dCurrentValue=new CDateTime(0);
      }
      oaTuple[iBaseColumnIndex]=dCurrentValue;
      double diff=CDateTime.computeDifference(dCurrentValue,baseReference,cunit,true);
      if (diff != 0) {
        iGroupIndex=iGroupingInterval == 0 ? iGroupIndex + 1 : (int)Math.floor(Math.abs(diff / iGroupingInterval));
      }
      if (!bFirst) {
        bGroupBreak=(iLastGroupIndex != iGroupIndex);
      }
      if (bGroupBreak || bFirst) {
        if (oaSummarizedTuple != null) {
          for (int i=0; i < iOrthogonalSeriesCount; i++) {
            oaSummarizedTuple[iaColumnIndexes[i]]=iafa[i].getAggregatedValue();
            iafa[i].initialize();
          }
          Object obj=oaTuple[iBaseColumnIndex];
          if (obj instanceof CDateTime) {
            baseReference=(CDateTime)obj;
          }
 else           if (obj instanceof Calendar) {
            baseReference=new CDateTime((Calendar)obj);
          }
 else           if (obj instanceof Date) {
            baseReference=new CDateTime((Date)obj);
          }
 else {
            baseReference=new CDateTime(0);
          }
          baseReference.clearBelow(cunit);
          iGroupIndex=0;
        }
 else {
          bFirst=false;
        }
        oaSummarizedTuple=oaTuple;
      }
 else {
        trashList.add(Integer.valueOf(j));
      }
      for (int i=0; i < iOrthogonalSeriesCount; i++) {
        try {
          iafa[i].accumulate(oaTuple[iaColumnIndexes[i]]);
        }
 catch (        IllegalArgumentException uiex) {
          throw new ChartException(ChartEnginePlugin.ID,ChartException.GENERATION,uiex);
        }
      }
      iLastGroupIndex=iGroupIndex;
    }
    if (oaSummarizedTuple != null) {
      for (int i=0; i < iOrthogonalSeriesCount; i++) {
        oaSummarizedTuple[iaColumnIndexes[i]]=iafa[i].getAggregatedValue();
        iafa[i].initialize();
      }
    }
    for (int i=0; i < trashList.size(); i++) {
      resultSet.remove(((Integer)trashList.get(i)).intValue() - i);
    }
    int groupChange=trashList.size();
    trashList.clear();
    if (iaBreaks != null && iaBreaks.length > 0 && groupChange > 0) {
      for (int j=k; j < iaBreaks.length; j++) {
        iaBreaks[j]-=groupChange;
      }
    }
    iStartIndex=iEndIndex - groupChange;
    totalRowCount-=groupChange;
  }
}

Fixed version (ground truth):
private void groupDateTime(List resultSet,int iBaseColumnIndex,int[] iaColumnIndexes,int[] iaBreaks,CDateTime ndeBaseReference,long iGroupingInterval,GroupingUnitType groupingUnit,IAggregateFunction[] iafa) throws ChartException {
  final int iOrthogonalSeriesCount=iaColumnIndexes.length;
  int cunit=GroupingUtil.groupingUnit2CDateUnit(groupingUnit);
  int iStartIndex=0, iEndIndex;
  int totalGroupCount=iaBreaks == null ? 1 : (iaBreaks.length + 1);
  int totalRowCount=resultSet.size();
  for (int k=0; k < totalGroupCount; k++) {
    if (k == totalGroupCount - 1) {
      iEndIndex=totalRowCount;
    }
 else {
      iEndIndex=iaBreaks[k];
    }
    CDateTime baseReference=ndeBaseReference;
    if (baseReference == null) {
      Object obj=((Object[])resultSet.get(iStartIndex))[iBaseColumnIndex];
      if (obj instanceof CDateTime) {
        baseReference=(CDateTime)obj;
      }
 else {
        baseReference=new CDateTime(0);
      }
    }
    baseReference.clearBelow(cunit);
    Object[] oaTuple, oaSummarizedTuple=null;
    int iGroupIndex=0, iLastGroupIndex=0;
    boolean bFirst=true, bGroupBreak=false;
    List trashList=new ArrayList();
    for (int j=iStartIndex; j < iEndIndex; j++) {
      oaTuple=(Object[])resultSet.get(j);
      CDateTime dCurrentValue=null;
      if (oaTuple[iBaseColumnIndex] != null) {
        Object obj=oaTuple[iBaseColumnIndex];
        if (obj instanceof CDateTime) {
          dCurrentValue=(CDateTime)obj;
        }
 else {
          dCurrentValue=new CDateTime(0);
        }
        dCurrentValue.clearBelow(cunit);
      }
 else {
        dCurrentValue=new CDateTime(0);
      }
      oaTuple[iBaseColumnIndex]=dCurrentValue;
      double diff=CDateTime.computeDifference(dCurrentValue,baseReference,cunit,true);
      if (diff != 0) {
        iGroupIndex=iGroupingInterval == 0 ? iGroupIndex + 1 : (int)Math.floor(Math.abs(diff / iGroupingInterval));
      }
      if (!bFirst) {
        bGroupBreak=(iLastGroupIndex != iGroupIndex);
      }
      if (bGroupBreak || bFirst) {
        if (oaSummarizedTuple != null) {
          for (int i=0; i < iOrthogonalSeriesCount; i++) {
            oaSummarizedTuple[iaColumnIndexes[i]]=iafa[i].getAggregatedValue();
            iafa[i].initialize();
          }
          Object obj=oaTuple[iBaseColumnIndex];
          if (obj instanceof CDateTime) {
            baseReference=(CDateTime)obj;
          }
 else {
            baseReference=new CDateTime(0);
          }
          baseReference.clearBelow(cunit);
          iGroupIndex=0;
        }
 else {
          bFirst=false;
        }
        oaSummarizedTuple=oaTuple;
      }
 else {
        trashList.add(Integer.valueOf(j));
      }
      for (int i=0; i < iOrthogonalSeriesCount; i++) {
        try {
          iafa[i].accumulate(oaTuple[iaColumnIndexes[i]]);
        }
 catch (        IllegalArgumentException uiex) {
          throw new ChartException(ChartEnginePlugin.ID,ChartException.GENERATION,uiex);
        }
      }
      iLastGroupIndex=iGroupIndex;
    }
    if (oaSummarizedTuple != null) {
      for (int i=0; i < iOrthogonalSeriesCount; i++) {
        oaSummarizedTuple[iaColumnIndexes[i]]=iafa[i].getAggregatedValue();
        iafa[i].initialize();
      }
    }
    for (int i=0; i < trashList.size(); i++) {
      resultSet.remove(((Integer)trashList.get(i)).intValue() - i);
    }
    int groupChange=trashList.size();
    trashList.clear();
    if (iaBreaks != null && iaBreaks.length > 0 && groupChange > 0) {
      for (int j=k; j < iaBreaks.length; j++) {
        iaBreaks[j]-=groupChange;
      }
    }
    iStartIndex=iEndIndex - groupChange;
    totalRowCount-=groupChange;
  }
}