Program: 77291
Project: 77291
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 {
  LinkedHashMap lhmLookup=new LinkedHashMap();
  Collection co=getRowExpressions(cm,iae);
  Iterator it=co.iterator();
  String sxp;
  int i=0;
  while (it.hasNext()) {
    sxp=(String)it.next();
    lhmLookup.put(sxp,new Integer(i++));
  }
  final int iColumnCount=i;
  final List liResultSet=new ArrayList();
  Object[] oaTuple;
  int iColumnIndex;
  boolean hasFirst=idre.first();
  if (hasFirst) {
    do {
      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);
  for (i=0; i < groupKeys.length; i++) {
    groupKeys[i].setKeyIndex(((Integer)lhmLookup.get(groupKeys[i].getKey())).intValue());
  }
  final ResultSetWrapper rsw=new ResultSetWrapper(lhmLookup.keySet(),liResultSet,groupKeys);
  SeriesDefinition sdGrouping=null;
  String[] saOrthogonalDataDefinitions=null;
  if (cm instanceof ChartWithAxes) {
    ArrayList alODD=new ArrayList(8);
    ChartWithAxes cwa=(ChartWithAxes)cm;
    Axis[] axaBase=cwa.getBaseAxes();
    Axis[] axaOrthogonal=null;
    Series SE;
    String sExpression;
    EList elSD, elDD;
    for (int j=0; j < axaBase.length; j++) {
      sdGrouping=(SeriesDefinition)axaBase[j].getSeriesDefinitions().get(0);
      axaOrthogonal=cwa.getOrthogonalAxes(axaBase[j],true);
      for (i=0; i < axaOrthogonal.length; i++) {
        elSD=axaOrthogonal[i].getSeriesDefinitions();
        for (int k=0; k < elSD.size(); k++) {
          SE=((SeriesDefinition)elSD.get(k)).getDesignTimeSeries();
          if (SE != null) {
            elDD=SE.getDataDefinition();
            for (int n=0; n < elDD.size(); n++) {
              sExpression=((Query)elDD.get(n)).getDefinition();
              if (sExpression != null && sExpression.trim().length() > 0 && !alODD.contains(sExpression)) {
                alODD.add(sExpression);
              }
            }
          }
        }
      }
    }
    saOrthogonalDataDefinitions=(String[])alODD.toArray(new String[alODD.size()]);
  }
 else   if (cm instanceof ChartWithoutAxes) {
    ArrayList alODD=new ArrayList(8);
    ChartWithoutAxes cwoa=(ChartWithoutAxes)cm;
    Series SE;
    String sExpression;
    EList elSD, elDD;
    sdGrouping=(SeriesDefinition)cwoa.getSeriesDefinitions().get(0);
    elSD=sdGrouping.getSeriesDefinitions();
    for (int k=0; k < elSD.size(); k++) {
      SE=((SeriesDefinition)elSD.get(k)).getDesignTimeSeries();
      if (SE != null) {
        elDD=SE.getDataDefinition();
        for (int n=0; n < elDD.size(); n++) {
          sExpression=((Query)elDD.get(n)).getDefinition();
          if (sExpression != null && sExpression.trim().length() > 0 && !alODD.contains(sExpression)) {
            alODD.add(sExpression);
          }
        }
      }
    }
    saOrthogonalDataDefinitions=(String[])alODD.toArray(new String[alODD.size()]);
  }
  rsw.applyBaseSeriesSortingAndGrouping(sdGrouping,saOrthogonalDataDefinitions);
  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 {
  LinkedHashMap lhmLookup=new LinkedHashMap();
  Collection co=getRowExpressions(cm,iae);
  Iterator it=co.iterator();
  String sxp;
  int i=0;
  while (it.hasNext()) {
    sxp=(String)it.next();
    lhmLookup.put(sxp,new Integer(i++));
  }
  final int iColumnCount=i;
  final List liResultSet=new ArrayList();
  Object[] oaTuple;
  int iColumnIndex;
  boolean hasFirst=idre.first();
  if (hasFirst) {
    do {
      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);
  for (i=0; i < groupKeys.length; i++) {
    groupKeys[i].setKeyIndex(((Integer)lhmLookup.get(groupKeys[i].getKey())).intValue());
  }
  final ResultSetWrapper rsw=new ResultSetWrapper(lhmLookup.keySet(),liResultSet,groupKeys);
  SeriesDefinition sdGrouping=null;
  String[] saOrthogonalDataDefinitions=null;
  if (cm instanceof ChartWithAxes) {
    ArrayList alODD=new ArrayList(8);
    ChartWithAxes cwa=(ChartWithAxes)cm;
    Axis[] axaBase=cwa.getBaseAxes();
    Axis[] axaOrthogonal=null;
    Series SE;
    String sExpression;
    EList elSD, elDD;
    for (int j=0; j < axaBase.length; j++) {
      sdGrouping=(SeriesDefinition)axaBase[j].getSeriesDefinitions().get(0);
      axaOrthogonal=cwa.getOrthogonalAxes(axaBase[j],true);
      for (i=0; i < axaOrthogonal.length; i++) {
        elSD=axaOrthogonal[i].getSeriesDefinitions();
        for (int k=0; k < elSD.size(); k++) {
          SE=((SeriesDefinition)elSD.get(k)).getDesignTimeSeries();
          if (SE != null) {
            elDD=SE.getDataDefinition();
            for (int n=0; n < elDD.size(); n++) {
              sExpression=((Query)elDD.get(n)).getDefinition();
              if (sExpression != null && sExpression.trim().length() > 0 && !alODD.contains(sExpression)) {
                alODD.add(sExpression);
              }
            }
          }
        }
      }
    }
    saOrthogonalDataDefinitions=(String[])alODD.toArray(new String[alODD.size()]);
  }
 else   if (cm instanceof ChartWithoutAxes) {
    ArrayList alODD=new ArrayList(8);
    ChartWithoutAxes cwoa=(ChartWithoutAxes)cm;
    Series SE;
    String sExpression;
    EList elSD, elDD;
    sdGrouping=(SeriesDefinition)cwoa.getSeriesDefinitions().get(0);
    elSD=sdGrouping.getSeriesDefinitions();
    for (int k=0; k < elSD.size(); k++) {
      SE=((SeriesDefinition)elSD.get(k)).getDesignTimeSeries();
      if (SE != null) {
        elDD=SE.getDataDefinition();
        for (int n=0; n < elDD.size(); n++) {
          sExpression=((Query)elDD.get(n)).getDefinition();
          if (sExpression != null && sExpression.trim().length() > 0 && !alODD.contains(sExpression)) {
            alODD.add(sExpression);
          }
        }
      }
    }
    saOrthogonalDataDefinitions=(String[])alODD.toArray(new String[alODD.size()]);
  }
  if (rsw.getRowCount() > 0) {
    rsw.applyBaseSeriesSortingAndGrouping(sdGrouping,saOrthogonalDataDefinitions);
  }
  return rsw;
}