Program: 76229
Project: 76229
Buggy source:
/** 
 * Uses IDataRowExpressionEvaluator to create a ResultSetWrapper
 * @return A wrapper of the chart resultset
 * @throws ChartException
 */
protected ResultSetWrapper mapToChartResultSet(IDataRowExpressionEvaluator idre,Chart cm) throws ChartException {
  GroupingLookupHelper lhmLookup=new GroupingLookupHelper(cm,iae);
  Collection co=lhmLookup.getExpressions();
  final int iColumnCount=co.size();
  final List liResultSet=new ArrayList();
  Object[] oaTuple;
  int iColumnIndex;
  Iterator it;
  if (idre.first()) {
    int count=0;
    final int MAX_ROW_COUNT=ChartUtil.getSupportedMaxRowCount();
    do {
      if (count++ > MAX_ROW_COUNT) {
        throw new ChartException(ChartEnginePlugin.ID,ChartException.DATA_BINDING,"String_Node_Str",new Object[]{new Integer(MAX_ROW_COUNT)},Messages.getResourceBundle());
      }
      oaTuple=new Object[iColumnCount];
      it=co.iterator();
      iColumnIndex=0;
      while (it.hasNext()) {
        oaTuple[iColumnIndex++]=idre.evaluate((String)it.next());
      }
      liResultSet.add(oaTuple);
    }
 while (idre.next());
  }
  final GroupKey[] groupKeys=findGroupKeys(cm,lhmLookup);
  final ResultSetWrapper rsw=new ResultSetWrapper(lhmLookup,liResultSet,groupKeys);
  SeriesDefinition sdBase=null;
  boolean bBaseGrouping=false;
  AggregationExpressionHelper aggHelper=new AggregationExpressionHelper();
  if (cm instanceof ChartWithAxes) {
    ChartWithAxes cwa=(ChartWithAxes)cm;
    Axis[] axaBase=cwa.getBaseAxes();
    Axis[] axaOrthogonal=null;
    for (int j=0; j < axaBase.length; j++) {
      sdBase=(SeriesDefinition)axaBase[j].getSeriesDefinitions().get(0);
      axaOrthogonal=cwa.getOrthogonalAxes(axaBase[j],true);
      bBaseGrouping=rsw.getRowCount() > 0 && sdBase.getGrouping() != null && sdBase.getGrouping().isEnabled();
      for (int i=0; i < axaOrthogonal.length; i++) {
        aggHelper.addSeriesDefinitions(axaOrthogonal[i].getSeriesDefinitions(),lhmLookup);
      }
    }
  }
 else   if (cm instanceof ChartWithoutAxes) {
    ChartWithoutAxes cwoa=(ChartWithoutAxes)cm;
    sdBase=(SeriesDefinition)cwoa.getSeriesDefinitions().get(0);
    bBaseGrouping=rsw.getRowCount() > 0 && sdBase.getGrouping() != null && sdBase.getGrouping().isEnabled();
    aggHelper.addSeriesDefinitions(sdBase.getSeriesDefinitions(),lhmLookup);
  }
  if (bBaseGrouping && aggHelper.getDataDefinitionsForBaseGrouping().size() > 0) {
    aggHelper.addAggregation(sdBase.getGrouping().getAggregateExpression(),aggHelper.getDataDefinitionsForBaseGrouping());
  }
  if (!aggHelper.isEmpty()) {
    rsw.applyBaseSeriesSortingAndGrouping(sdBase,aggHelper.getAggregations(),aggHelper.getDataDefinitions());
  }
  aggHelper.dispose();
  return rsw;
}

Fixed version (ground truth):
/** 
 * Uses IDataRowExpressionEvaluator to create a ResultSetWrapper
 * @return A wrapper of the chart resultset
 * @throws ChartException
 */
protected ResultSetWrapper mapToChartResultSet(IDataRowExpressionEvaluator idre,Chart cm) throws ChartException {
  GroupingLookupHelper lhmLookup=new GroupingLookupHelper(cm,iae);
  Collection co=lhmLookup.getExpressions();
  final int iColumnCount=co.size();
  final List liResultSet=new ArrayList();
  Object[] oaTuple;
  int iColumnIndex;
  Iterator it;
  if (idre.first()) {
    int count=0;
    final int MAX_ROW_COUNT=ChartUtil.getSupportedMaxRowCount();
    do {
      if (count++ > MAX_ROW_COUNT) {
        throw new ChartException(ChartEnginePlugin.ID,ChartException.DATA_BINDING,"String_Node_Str",new Object[]{new Integer(MAX_ROW_COUNT)},Messages.getResourceBundle());
      }
      oaTuple=new Object[iColumnCount];
      it=co.iterator();
      iColumnIndex=0;
      while (it.hasNext()) {
        oaTuple[iColumnIndex++]=idre.evaluate((String)it.next());
      }
      liResultSet.add(oaTuple);
    }
 while (idre.next());
  }
  final GroupKey[] groupKeys=findGroupKeys(cm,lhmLookup);
  final ResultSetWrapper rsw=new ResultSetWrapper(lhmLookup,liResultSet,groupKeys);
  SeriesDefinition sdBase=null;
  boolean bBaseGrouping=false;
  AggregationExpressionHelper aggHelper=new AggregationExpressionHelper();
  if (cm instanceof ChartWithAxes) {
    ChartWithAxes cwa=(ChartWithAxes)cm;
    Axis[] axaBase=cwa.getBaseAxes();
    Axis[] axaOrthogonal=null;
    for (int j=0; j < axaBase.length; j++) {
      sdBase=(SeriesDefinition)axaBase[j].getSeriesDefinitions().get(0);
      axaOrthogonal=cwa.getOrthogonalAxes(axaBase[j],true);
      bBaseGrouping=rsw.getRowCount() > 0 && sdBase.getGrouping() != null && sdBase.getGrouping().isEnabled();
      for (int i=0; i < axaOrthogonal.length; i++) {
        aggHelper.addSeriesDefinitions(axaOrthogonal[i].getSeriesDefinitions(),lhmLookup);
      }
    }
  }
 else   if (cm instanceof ChartWithoutAxes) {
    ChartWithoutAxes cwoa=(ChartWithoutAxes)cm;
    sdBase=(SeriesDefinition)cwoa.getSeriesDefinitions().get(0);
    bBaseGrouping=rsw.getRowCount() > 0 && sdBase.getGrouping() != null && sdBase.getGrouping().isEnabled();
    aggHelper.addSeriesDefinitions(sdBase.getSeriesDefinitions(),lhmLookup);
  }
  if (bBaseGrouping && aggHelper.getDataDefinitionsForBaseGrouping().size() > 0) {
    aggHelper.addAggregation(sdBase.getGrouping().getAggregateExpression(),aggHelper.getDataDefinitionsForBaseGrouping());
  }
  rsw.applyBaseSeriesSortingAndGrouping(sdBase,aggHelper.getAggregations(),aggHelper.getDataDefinitions());
  aggHelper.dispose();
  return rsw;
}