Program: 71760
Project: 71760
Buggy source:
private double[] computeVerticalByCategory(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 columnList=new ArrayList();
  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()) {
      return null;
    }
    sdBase=(SeriesDefinition)axPrimaryBase.getSeriesDefinitions().get(0);
  }
 else   if (cm instanceof ChartWithoutAxes) {
    if (((ChartWithoutAxes)cm).getSeriesDefinitions().isEmpty()) {
      return null;
    }
    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 (dX + dW > legendData.dAvailableWidth + legendData.dSafeSpacing) {
        columnList.clear();
        break all;
      }
 else {
        if (dY + dH > legendData.dAvailableHeight + legendData.dSafeSpacing) {
          legendData.legendItems.addAll(columnList);
          columnList.clear();
          dX+=dMaxW;
          dMaxH=Math.max(dMaxH,dY);
          dY=0;
          dMaxW=0;
          bRedo=true;
        }
 else {
          dMaxW=Math.max(dW,dMaxW);
          dY+=dH;
          bRedo=false;
        }
      }
    }
    columnList.add(new LegendItemHints(categoryIndex,new Point(dX,dY - dH),dW - legendData.dHorizonalReservedSpace,laiLegend.getHeight(),laiLegend.getCaption(),bNeedInvert ? dsiBase.size() - 1 - pos : pos));
  }
  legendData.legendItems.addAll(columnList);
  columnList.clear();
  double dWidth=dX + dMaxW;
  double dHeight=Math.max(dMaxH,dY);
  return new double[]{dWidth,dHeight};
}

Fixed version (ground truth):
private double[] computeVerticalByCategory(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 columnList=new ArrayList();
  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()) {
      return null;
    }
    sdBase=(SeriesDefinition)axPrimaryBase.getSeriesDefinitions().get(0);
  }
 else   if (cm instanceof ChartWithoutAxes) {
    if (((ChartWithoutAxes)cm).getSeriesDefinitions().isEmpty()) {
      return null;
    }
    sdBase=(SeriesDefinition)((ChartWithoutAxes)cm).getSeriesDefinitions().get(0);
  }
  Series seBase;
  if (sdBase.getRunTimeSeries().size() == 0) {
    return new double[]{0,0};
  }
 else {
    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 (dX + dW > legendData.dAvailableWidth + legendData.dSafeSpacing) {
        columnList.clear();
        break all;
      }
 else {
        if (dY + dH > legendData.dAvailableHeight + legendData.dSafeSpacing) {
          legendData.legendItems.addAll(columnList);
          columnList.clear();
          dX+=dMaxW;
          dMaxH=Math.max(dMaxH,dY);
          dY=0;
          dMaxW=0;
          bRedo=true;
        }
 else {
          dMaxW=Math.max(dW,dMaxW);
          dY+=dH;
          bRedo=false;
        }
      }
    }
    columnList.add(new LegendItemHints(categoryIndex,new Point(dX,dY - dH),dW - legendData.dHorizonalReservedSpace,laiLegend.getHeight(),laiLegend.getCaption(),bNeedInvert ? dsiBase.size() - 1 - pos : pos));
  }
  legendData.legendItems.addAll(columnList);
  columnList.clear();
  double dWidth=dX + dMaxW;
  double dHeight=Math.max(dMaxH,dY);
  return new double[]{dWidth,dHeight};
}