Program: 70973
Project: 70973
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 {
  ResultSetWrapper rsw=null;
  GroupingLookupHelper lhmLookup=new GroupingLookupHelper(cm,iae,rtc.getULocale());
  List liResultSet=null;
  List co=null;
  if (idre instanceof AbstractGroupedDataRowExpressionEvaluator) {
    co=((AbstractGroupedDataRowExpressionEvaluator)idre).getExpressions(lhmLookup,rtc.isSharingQuery());
  }
 else {
    co=lhmLookup.getExpressions();
  }
  try {
    liResultSet=evaluateRowSet(idre,co.toArray());
  }
 catch (  Exception e) {
    if (e instanceof ChartException) {
      throw (ChartException)e;
    }
    throw new ChartException(ChartEnginePlugin.ID,ChartException.GENERATION,e);
  }
  final GroupKey[] orthogonalGroupKeys=findGroupKeys(cm,lhmLookup);
  if (idre instanceof IGroupedDataRowExpressionEvaluator && ((IGroupedDataRowExpressionEvaluator)idre).getGroupBreaks(0) != null) {
    int[] groupBreaks=new int[]{};
    if (orthogonalGroupKeys != null && orthogonalGroupKeys.length > 0) {
      groupBreaks=((IGroupedDataRowExpressionEvaluator)idre).getGroupBreaks(0);
    }
    formatBaseSeriesData(cm,lhmLookup,liResultSet);
    rsw=new ResultSetWrapper(lhmLookup,liResultSet,orthogonalGroupKeys,groupBreaks);
  }
 else {
    rsw=new ResultSetWrapper(lhmLookup,liResultSet,orthogonalGroupKeys);
    SeriesDefinition sdBase=null;
    SeriesDefinition sdValue=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);
        }
      }
      sdValue=(SeriesDefinition)cwa.getOrthogonalAxes(axaBase[0],true)[0].getSeriesDefinitions().get(0);
    }
 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);
      sdValue=(SeriesDefinition)sdBase.getSeriesDefinitions().get(0);
    }
    if (bBaseGrouping && aggHelper.getDataDefinitionsForBaseGrouping().size() > 0) {
      aggHelper.addAggregation(sdBase.getGrouping().getAggregateExpression(),aggHelper.getDataDefinitionsForBaseGrouping());
    }
    String[] aggregationExp=aggHelper.getAggregations();
    String[] saExpressionKeys=aggHelper.getDataDefinitions();
    if (idre instanceof IGroupedDataRowExpressionEvaluator) {
      if (((IGroupedDataRowExpressionEvaluator)idre).needOptionalGrouping()) {
        rsw.applyValueSeriesGroupingNSorting(sdValue,aggregationExp,saExpressionKeys);
      }
      if (((IGroupedDataRowExpressionEvaluator)idre).needCategoryGrouping()) {
        rsw.applyBaseSeriesSortingAndGrouping(sdBase,aggregationExp,saExpressionKeys);
      }
    }
 else {
      rsw.applyValueSeriesGroupingNSorting(sdValue,aggregationExp,saExpressionKeys);
      rsw.applyBaseSeriesSortingAndGrouping(sdBase,aggregationExp,saExpressionKeys);
    }
    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 {
  ResultSetWrapper rsw=null;
  GroupingLookupHelper lhmLookup=new GroupingLookupHelper(cm,iae,rtc,idre);
  List liResultSet=null;
  List<String> co=null;
  co=lhmLookup.getExpressions();
  try {
    liResultSet=evaluateRowSet(idre,co.toArray());
  }
 catch (  Exception e) {
    if (e instanceof ChartException) {
      throw (ChartException)e;
    }
    throw new ChartException(ChartEnginePlugin.ID,ChartException.GENERATION,e);
  }
  final GroupKey[] orthogonalGroupKeys=findGroupKeys(cm,lhmLookup);
  if (idre instanceof IGroupedDataRowExpressionEvaluator && ((IGroupedDataRowExpressionEvaluator)idre).getGroupBreaks(0) != null) {
    int[] groupBreaks=new int[]{};
    if (orthogonalGroupKeys != null && orthogonalGroupKeys.length > 0) {
      groupBreaks=((IGroupedDataRowExpressionEvaluator)idre).getGroupBreaks(0);
    }
    formatBaseSeriesData(cm,lhmLookup,liResultSet);
    rsw=new ResultSetWrapper(lhmLookup,liResultSet,orthogonalGroupKeys,groupBreaks);
  }
 else {
    rsw=new ResultSetWrapper(lhmLookup,liResultSet,orthogonalGroupKeys);
    SeriesDefinition sdBase=null;
    SeriesDefinition sdValue=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=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);
        }
      }
      sdValue=cwa.getOrthogonalAxes(axaBase[0],true)[0].getSeriesDefinitions().get(0);
    }
 else     if (cm instanceof ChartWithoutAxes) {
      ChartWithoutAxes cwoa=(ChartWithoutAxes)cm;
      sdBase=cwoa.getSeriesDefinitions().get(0);
      bBaseGrouping=rsw.getRowCount() > 0 && sdBase.getGrouping() != null && sdBase.getGrouping().isEnabled();
      aggHelper.addSeriesDefinitions(sdBase.getSeriesDefinitions(),lhmLookup);
      sdValue=sdBase.getSeriesDefinitions().get(0);
    }
    if (bBaseGrouping && aggHelper.getDataDefinitionsForBaseGrouping().size() > 0) {
      aggHelper.addAggregation(sdBase.getGrouping().getAggregateExpression(),aggHelper.getDataDefinitionsForBaseGrouping());
    }
    String[] aggregationExp=aggHelper.getAggregations();
    String[] saExpressionKeys=aggHelper.getDataDefinitions();
    if (idre instanceof IGroupedDataRowExpressionEvaluator) {
      if (((IGroupedDataRowExpressionEvaluator)idre).needOptionalGrouping()) {
        rsw.applyValueSeriesGroupingNSorting(sdValue,aggregationExp,saExpressionKeys);
      }
      if (((IGroupedDataRowExpressionEvaluator)idre).needCategoryGrouping()) {
        rsw.applyBaseSeriesSortingAndGrouping(sdBase,aggregationExp,saExpressionKeys);
      }
    }
 else {
      rsw.applyValueSeriesGroupingNSorting(sdValue,aggregationExp,saExpressionKeys);
      rsw.applyBaseSeriesSortingAndGrouping(sdBase,aggregationExp,saExpressionKeys);
    }
    aggHelper.dispose();
  }
  return rsw;
}