Program: 71373
Project: 71373
Buggy source:
private double[] computeHorizalByCategory(IDisplayServer xs,Chart cm,RunTimeContext rtc,ITextMetrics itm,Label la,LegendData legendData,boolean bNeedInvert) throws ChartException {
  double dX=0, dY=0;
  double dW=0, dH=0;
  double dMaxW=0, dMaxH=0;
  ArrayList<LegendItemHints> columnList=new ArrayList<LegendItemHints>();
  LabelItem laiLegend=new LabelItem(xs,rtc,itm,la,legendData.maxWrappingSize);
  SeriesDefinition sdBase=null;
  if (cm instanceof ChartWithAxes) {
    final Axis axPrimaryBase=((ChartWithAxes)cm).getBaseAxes()[0];
    if (axPrimaryBase.getSeriesDefinitions().isEmpty()) {
      throw new ChartException(ChartEnginePlugin.ID,ChartException.GENERATION,"String_Node_Str",Messages.getResourceBundle(xs.getULocale()));
    }
    sdBase=(SeriesDefinition)axPrimaryBase.getSeriesDefinitions().get(0);
  }
 else   if (cm instanceof ChartWithoutAxes) {
    if (((ChartWithoutAxes)cm).getSeriesDefinitions().isEmpty()) {
      throw new ChartException(ChartEnginePlugin.ID,ChartException.GENERATION,"String_Node_Str",Messages.getResourceBundle(xs.getULocale()));
    }
    sdBase=(SeriesDefinition)((ChartWithoutAxes)cm).getSeriesDefinitions().get(0);
  }
  Series seBase=(Series)sdBase.getRunTimeSeries().get(0);
  DataSetIterator dsiBase=createDataSetIterator(seBase,cm);
  FormatSpecifier fs=null;
  if (sdBase != null) {
    fs=sdBase.getFormatSpecifier();
  }
  int pos=-1;
  dsiBase.reverse(bNeedInvert);
  boolean bHasMoreData=true;
  all:   while (bHasMoreData) {
    int categoryIndex;
    if (dsiBase.hasNext()) {
      Object obj=dsiBase.next();
      obj=getNonEmptyValue(obj,IConstants.ONE_SPACE);
      while (!isValidValue(obj) && dsiBase.hasNext()) {
        obj=dsiBase.next();
      }
      pos++;
      if (legendData.bMinSliceApplied && Arrays.binarySearch(legendData.filteredMinSliceEntry,pos) >= 0) {
        continue;
      }
      laiLegend.setText(obj,fs);
      categoryIndex=LEGEND_ENTRY;
    }
 else     if (legendData.bMinSliceApplied) {
      laiLegend.setText(legendData.sMinSliceLabel,null);
      categoryIndex=LEGEND_MINSLICE_ENTRY;
      bHasMoreData=false;
      pos++;
    }
 else {
      break;
    }
    boolean bRedo=true;
    for (int iLoopLimit=2; bRedo && iLoopLimit > 0; iLoopLimit--) {
      double[] dsize=getItemSizeCata(laiLegend,legendData,dX);
      dW=dsize[0];
      dH=dsize[1];
      if (!hasPlaceForOneItem(dW,dH,legendData)) {
        break all;
      }
      if (dY + dH > legendData.dAvailableHeight + legendData.dSafeSpacing) {
        columnList.clear();
        break all;
      }
 else {
        if (dX + dW > legendData.dAvailableWidth + legendData.dSafeSpacing) {
          legendData.legendItems.addAll(columnList);
          columnList.clear();
          dY+=dMaxH;
          dMaxH=0;
          dMaxW=Math.max(dMaxW,dX);
          dX=0;
          laiLegend.restoreOriginalText(fs);
          bRedo=true;
        }
 else {
          dMaxH=Math.max(dH,dMaxH);
          dX+=dW;
          bRedo=false;
        }
      }
    }
    columnList.add(new LegendItemHints(categoryIndex,new Point(dX - dW,dY),dW - legendData.dHorizonalReservedSpace,laiLegend.getHeight(),laiLegend.getCaption(),bNeedInvert ? dsiBase.size() - 1 - pos : pos,sdBase,seBase));
  }
  legendData.legendItems.addAll(columnList);
  columnList.clear();
  double dHeight=dMaxH + dY;
  double dWidth=Math.max(dMaxW,dX);
  return new double[]{dWidth,dHeight};
}

Fixed version (ground truth):
private double[] computeHorizalByCategory(IDisplayServer xs,Chart cm,RunTimeContext rtc,ITextMetrics itm,Label la,LegendData legendData,boolean bNeedInvert) throws ChartException {
  double dX=0, dY=0;
  double dW=0, dH=0;
  double dMaxW=0, dMaxH=0;
  ArrayList<LegendItemHints> columnList=new ArrayList<LegendItemHints>();
  LabelItem laiLegend=new LabelItem(xs,rtc,itm,la,legendData.maxWrappingSize);
  SeriesDefinition sdBase=null;
  if (cm instanceof ChartWithAxes) {
    final Axis axPrimaryBase=((ChartWithAxes)cm).getBaseAxes()[0];
    if (axPrimaryBase.getSeriesDefinitions().isEmpty()) {
      throw new ChartException(ChartEnginePlugin.ID,ChartException.GENERATION,"String_Node_Str",Messages.getResourceBundle(xs.getULocale()));
    }
    sdBase=(SeriesDefinition)axPrimaryBase.getSeriesDefinitions().get(0);
  }
 else   if (cm instanceof ChartWithoutAxes) {
    if (((ChartWithoutAxes)cm).getSeriesDefinitions().isEmpty()) {
      throw new ChartException(ChartEnginePlugin.ID,ChartException.GENERATION,"String_Node_Str",Messages.getResourceBundle(xs.getULocale()));
    }
    sdBase=(SeriesDefinition)((ChartWithoutAxes)cm).getSeriesDefinitions().get(0);
  }
  Series seBase=(Series)sdBase.getRunTimeSeries().get(0);
  DataSetIterator dsiBase=createDataSetIterator(seBase,cm);
  FormatSpecifier fs=null;
  if (sdBase != null) {
    fs=sdBase.getFormatSpecifier();
  }
  int pos=-1;
  boolean bDataReverse=bNeedInvert;
  if (cm instanceof ChartWithAxes) {
    ChartWithAxes cwa=(ChartWithAxes)cm;
    bDataReverse=ChartUtil.XOR(bNeedInvert,cwa.isReverseCategory());
  }
  dsiBase.reverse(bDataReverse);
  boolean bHasMoreData=true;
  all:   while (bHasMoreData) {
    int categoryIndex;
    if (dsiBase.hasNext()) {
      Object obj=dsiBase.next();
      obj=getNonEmptyValue(obj,IConstants.ONE_SPACE);
      while (!isValidValue(obj) && dsiBase.hasNext()) {
        obj=dsiBase.next();
      }
      pos++;
      if (legendData.bMinSliceApplied && Arrays.binarySearch(legendData.filteredMinSliceEntry,pos) >= 0) {
        continue;
      }
      laiLegend.setText(obj,fs);
      categoryIndex=LEGEND_ENTRY;
    }
 else     if (legendData.bMinSliceApplied) {
      laiLegend.setText(legendData.sMinSliceLabel,null);
      categoryIndex=LEGEND_MINSLICE_ENTRY;
      bHasMoreData=false;
      pos++;
    }
 else {
      break;
    }
    boolean bRedo=true;
    for (int iLoopLimit=2; bRedo && iLoopLimit > 0; iLoopLimit--) {
      double[] dsize=getItemSizeCata(laiLegend,legendData,dX);
      dW=dsize[0];
      dH=dsize[1];
      if (!hasPlaceForOneItem(dW,dH,legendData)) {
        break all;
      }
      if (dY + dH > legendData.dAvailableHeight + legendData.dSafeSpacing) {
        columnList.clear();
        break all;
      }
 else {
        if (dX + dW > legendData.dAvailableWidth + legendData.dSafeSpacing) {
          legendData.legendItems.addAll(columnList);
          columnList.clear();
          dY+=dMaxH;
          dMaxH=0;
          dMaxW=Math.max(dMaxW,dX);
          dX=0;
          laiLegend.restoreOriginalText(fs);
          bRedo=true;
        }
 else {
          dMaxH=Math.max(dH,dMaxH);
          dX+=dW;
          bRedo=false;
        }
      }
    }
    columnList.add(new LegendItemHints(categoryIndex,new Point(dX - dW,dY),dW - legendData.dHorizonalReservedSpace,laiLegend.getHeight(),laiLegend.getCaption(),bNeedInvert ? dsiBase.size() - 1 - pos : pos,sdBase,seBase));
  }
  legendData.legendItems.addAll(columnList);
  columnList.clear();
  double dHeight=dMaxH + dY;
  double dWidth=Math.max(dMaxW,dX);
  return new double[]{dWidth,dHeight};
}