Program: 69610
Project: 69610
Buggy source:
/** 
 * Computes the size of the legend. Note the computation relies on the title size, so the title block must be layouted first before this.
 * @param lg
 * @param sea
 * @throws ChartException
 */
public final Size compute(IDisplayServer xs,Chart cm,SeriesDefinition[] seda,RunTimeContext rtc) throws ChartException {
  final Legend lg=cm.getLegend();
  LegendData lgData=new LegendData(xs,cm,seda,rtc);
  initAvailableSize(lgData);
  boolean bMinSliceDefined=false;
  if (cm instanceof ChartWithoutAxes) {
    bMinSliceDefined=((ChartWithoutAxes)cm).isSetMinSlice();
    lgData.sMinSliceLabel=((ChartWithoutAxes)cm).getMinSliceLabel();
    if (lgData.sMinSliceLabel == null || lgData.sMinSliceLabel.length() == 0) {
      lgData.sMinSliceLabel=IConstants.UNDEFINED_STRING;
    }
 else {
      lgData.sMinSliceLabel=rtc.externalizedMessage(lgData.sMinSliceLabel);
    }
  }
  if (bMinSliceDefined && lgData.bPaletteByCategory && cm instanceof ChartWithoutAxes) {
    calculateExtraLegend(cm,rtc,lgData);
  }
  Size titleSize=getTitleSize(lgData);
  double[] size=null;
  Boolean bDataEmpty=rtc.getState(RunTimeContext.StateKey.DATA_EMPTY_KEY);
  if (bDataEmpty == null) {
    bDataEmpty=false;
  }
  if (!bDataEmpty) {
    ContentProvider cProvider=ContentProvider.newInstance(lgData);
    ContentPlacer cPlacer=ContentPlacer.newInstance(lgData);
    LegendItemHints lih;
    while ((lih=cProvider.nextContent()) != null) {
      if (!cPlacer.placeContent(lih)) {
        break;
      }
    }
    cPlacer.finishPlacing();
    size=cPlacer.getSize();
  }
  if (size == null) {
    size=new double[]{0,0};
  }
  double dWidth=size[0], dHeight=size[1];
  if (titleSize != null) {
    int iTitlePos=lgData.lg.getTitlePosition().getValue();
    if (iTitlePos == Position.ABOVE || iTitlePos == Position.BELOW) {
      dWidth=Math.max(dWidth,titleSize.getWidth());
      dHeight=dHeight + titleSize.getHeight();
    }
 else {
      dWidth=dWidth + titleSize.getWidth();
      dHeight=Math.max(dHeight,titleSize.getHeight());
    }
  }
  if (rtc != null) {
    List<LegendItemHints> legendItems=lgData.legendItems;
    LegendItemHints[] liha=legendItems.toArray(new LegendItemHints[legendItems.size()]);
    LegendLayoutHints lilh=new LegendLayoutHints(SizeImpl.create(dWidth,dHeight),titleSize,lgData.laTitle,lgData.bMinSliceApplied,lgData.sMinSliceLabel,liha);
    rtc.setLegendLayoutHints(lilh);
  }
  sz=SizeImpl.create(dWidth,dHeight);
  return sz;
}

Fixed version (ground truth):
/** 
 * Computes the size of the legend. Note the computation relies on the title size, so the title block must be layouted first before this.
 * @param lg
 * @param sea
 * @throws ChartException
 */
public final Size compute(IDisplayServer xs,Chart cm,SeriesDefinition[] seda,RunTimeContext rtc) throws ChartException {
  LegendData lgData=new LegendData(xs,cm,seda,rtc);
  initAvailableSize(lgData);
  boolean bMinSliceDefined=false;
  if (cm instanceof ChartWithoutAxes) {
    bMinSliceDefined=((ChartWithoutAxes)cm).isSetMinSlice();
    lgData.sMinSliceLabel=((ChartWithoutAxes)cm).getMinSliceLabel();
    if (lgData.sMinSliceLabel == null || lgData.sMinSliceLabel.length() == 0) {
      lgData.sMinSliceLabel=IConstants.UNDEFINED_STRING;
    }
 else {
      lgData.sMinSliceLabel=rtc.externalizedMessage(lgData.sMinSliceLabel);
    }
  }
  if (bMinSliceDefined && lgData.bPaletteByCategory && cm instanceof ChartWithoutAxes) {
    calculateExtraLegend(cm,rtc,lgData);
  }
  Size titleSize=getTitleSize(lgData);
  double[] size=null;
  Boolean bDataEmpty=rtc.getState(RunTimeContext.StateKey.DATA_EMPTY_KEY);
  if (bDataEmpty == null) {
    bDataEmpty=false;
  }
  if (!bDataEmpty) {
    ContentProvider cProvider=ContentProvider.newInstance(lgData);
    ContentPlacer cPlacer=ContentPlacer.newInstance(lgData);
    LegendItemHints lih;
    while ((lih=cProvider.nextContent()) != null) {
      if (!cPlacer.placeContent(lih)) {
        break;
      }
    }
    cPlacer.finishPlacing();
    size=cPlacer.getSize();
  }
  if (size == null) {
    size=new double[]{0,0};
  }
  double dWidth=size[0], dHeight=size[1];
  if (titleSize != null) {
    int iTitlePos=lgData.lg.getTitlePosition().getValue();
    if (iTitlePos == Position.ABOVE || iTitlePos == Position.BELOW) {
      dWidth=Math.max(dWidth,titleSize.getWidth());
      dHeight=dHeight + titleSize.getHeight();
    }
 else {
      dWidth=dWidth + titleSize.getWidth();
      dHeight=Math.max(dHeight,titleSize.getHeight());
    }
  }
  if (rtc != null) {
    List<LegendItemHints> legendItems=lgData.legendItems;
    LegendItemHints[] liha=legendItems.toArray(new LegendItemHints[legendItems.size()]);
    LegendLayoutHints lilh=new LegendLayoutHints(SizeImpl.create(dWidth,dHeight),titleSize,lgData.laTitle,lgData.bMinSliceApplied,lgData.sMinSliceLabel,liha);
    rtc.setLegendLayoutHints(lilh);
  }
  sz=SizeImpl.create(dWidth,dHeight);
  return sz;
}