Program: 71324
Project: 71324
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();
  if (!lg.isSetOrientation()) {
    throw new ChartException(ChartEnginePlugin.ID,ChartException.GENERATION,"String_Node_Str",Messages.getResourceBundle(xs.getULocale()));
  }
  if (!lg.isSetDirection()) {
    throw new ChartException(ChartEnginePlugin.ID,ChartException.GENERATION,"String_Node_Str",Messages.getResourceBundle(xs.getULocale()));
  }
  LegendData legendData=new LegendData(xs,cm,seda,rtc);
  initAvailableSize(legendData);
  boolean bMinSliceDefined=false;
  if (cm instanceof ChartWithoutAxes) {
    bMinSliceDefined=((ChartWithoutAxes)cm).isSetMinSlice();
    legendData.sMinSliceLabel=((ChartWithoutAxes)cm).getMinSliceLabel();
    if (legendData.sMinSliceLabel == null || legendData.sMinSliceLabel.length() == 0) {
      legendData.sMinSliceLabel=IConstants.UNDEFINED_STRING;
    }
 else {
      legendData.sMinSliceLabel=rtc.externalizedMessage(legendData.sMinSliceLabel);
    }
  }
  if (bMinSliceDefined && legendData.bPaletteByCategory && cm instanceof ChartWithoutAxes) {
    calculateExtraLegend(cm,rtc,legendData);
  }
  Label lgTitle=lg.getTitle();
  Size titleSize=null;
  BoundingBox titleBounding=null;
  int iTitlePos=-1;
  if (lgTitle != null && lgTitle.isSetVisible() && lgTitle.isVisible()) {
    lgTitle=LabelImpl.copyInstance(lgTitle);
    final String sPreviousValue=lgTitle.getCaption().getValue();
    lgTitle.getCaption().setValue(rtc.externalizedMessage(sPreviousValue));
    titleBounding=Methods.computeLabelSize(xs,lgTitle);
    iTitlePos=lg.getTitlePosition().getValue();
    if (rtc.isRightToLeft()) {
      if (iTitlePos == Position.LEFT) {
        iTitlePos=Position.RIGHT;
      }
 else       if (iTitlePos == Position.RIGHT) {
        iTitlePos=Position.LEFT;
      }
    }
    double shadowness=3 * legendData.dScale;
switch (iTitlePos) {
case Position.ABOVE:
case Position.BELOW:
      legendData.dAvailableHeight-=titleBounding.getHeight() + 2 * shadowness;
    break;
case Position.LEFT:
case Position.RIGHT:
  legendData.dAvailableWidth-=titleBounding.getWidth() + 2 * shadowness;
break;
}
titleSize=SizeImpl.create(titleBounding.getWidth() + 2 * shadowness,titleBounding.getHeight() + 2 * shadowness);
}
double[] size=null;
ContentProvider cProvider=ContentProvider.newInstance(legendData);
ContentPlacer cPlacer=ContentPlacer.newInstance(legendData);
LegendItemHints lih;
while ((lih=cProvider.nextContent()) != null) {
if (!cPlacer.placeContent(lih)) {
break;
}
}
cPlacer.finishPlacing();
size=cPlacer.getSize();
if (size == null) {
return SizeImpl.create(0,0);
}
double dWidth=size[0], dHeight=size[1];
if (iTitlePos != -1) {
double shadowness=3 * legendData.dScale;
switch (iTitlePos) {
case Position.ABOVE:
case Position.BELOW:
dHeight+=titleBounding.getHeight() + 2 * shadowness;
dWidth=Math.max(dWidth,titleBounding.getWidth() + 2 * shadowness);
break;
case Position.LEFT:
case Position.RIGHT:
dWidth+=titleBounding.getWidth() + 2 * shadowness;
dHeight=Math.max(dHeight,titleBounding.getHeight() + 2 * shadowness);
break;
}
}
if (rtc != null) {
List<LegendItemHints> legendItems=legendData.legendItems;
LegendItemHints[] liha=legendItems.toArray(new LegendItemHints[legendItems.size()]);
LegendLayoutHints lilh=new LegendLayoutHints(SizeImpl.create(dWidth,dHeight),titleSize,legendData.bMinSliceApplied,legendData.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 {
  final Legend lg=cm.getLegend();
  if (!lg.isSetOrientation()) {
    throw new ChartException(ChartEnginePlugin.ID,ChartException.GENERATION,"String_Node_Str",Messages.getResourceBundle(xs.getULocale()));
  }
  if (!lg.isSetDirection()) {
    throw new ChartException(ChartEnginePlugin.ID,ChartException.GENERATION,"String_Node_Str",Messages.getResourceBundle(xs.getULocale()));
  }
  LegendData legendData=new LegendData(xs,cm,seda,rtc);
  initAvailableSize(legendData);
  boolean bMinSliceDefined=false;
  if (cm instanceof ChartWithoutAxes) {
    bMinSliceDefined=((ChartWithoutAxes)cm).isSetMinSlice();
    legendData.sMinSliceLabel=((ChartWithoutAxes)cm).getMinSliceLabel();
    if (legendData.sMinSliceLabel == null || legendData.sMinSliceLabel.length() == 0) {
      legendData.sMinSliceLabel=IConstants.UNDEFINED_STRING;
    }
 else {
      legendData.sMinSliceLabel=rtc.externalizedMessage(legendData.sMinSliceLabel);
    }
  }
  if (bMinSliceDefined && legendData.bPaletteByCategory && cm instanceof ChartWithoutAxes) {
    calculateExtraLegend(cm,rtc,legendData);
  }
  Label lgTitle=lg.getTitle();
  Size titleSize=null;
  BoundingBox titleBounding=null;
  int iTitlePos=-1;
  if (lgTitle != null && lgTitle.isSetVisible() && lgTitle.isVisible()) {
    lgTitle=LabelImpl.copyInstance(lgTitle);
    final String sPreviousValue=lgTitle.getCaption().getValue();
    lgTitle.getCaption().setValue(rtc.externalizedMessage(sPreviousValue));
    titleBounding=Methods.computeLabelSize(xs,lgTitle,0,null);
    iTitlePos=lg.getTitlePosition().getValue();
    if (rtc.isRightToLeft()) {
      if (iTitlePos == Position.LEFT) {
        iTitlePos=Position.RIGHT;
      }
 else       if (iTitlePos == Position.RIGHT) {
        iTitlePos=Position.LEFT;
      }
    }
    double shadowness=3 * legendData.dScale;
switch (iTitlePos) {
case Position.ABOVE:
case Position.BELOW:
      legendData.dAvailableHeight-=titleBounding.getHeight() + 2 * shadowness;
    break;
case Position.LEFT:
case Position.RIGHT:
  legendData.dAvailableWidth-=titleBounding.getWidth() + 2 * shadowness;
break;
}
titleSize=SizeImpl.create(titleBounding.getWidth() + 2 * shadowness,titleBounding.getHeight() + 2 * shadowness);
}
double[] size=null;
ContentProvider cProvider=ContentProvider.newInstance(legendData);
ContentPlacer cPlacer=ContentPlacer.newInstance(legendData);
LegendItemHints lih;
while ((lih=cProvider.nextContent()) != null) {
if (!cPlacer.placeContent(lih)) {
break;
}
}
cPlacer.finishPlacing();
size=cPlacer.getSize();
if (size == null) {
return SizeImpl.create(0,0);
}
double dWidth=size[0], dHeight=size[1];
if (iTitlePos != -1) {
double shadowness=3 * legendData.dScale;
switch (iTitlePos) {
case Position.ABOVE:
case Position.BELOW:
dHeight+=titleBounding.getHeight() + 2 * shadowness;
dWidth=Math.max(dWidth,titleBounding.getWidth() + 2 * shadowness);
break;
case Position.LEFT:
case Position.RIGHT:
dWidth+=titleBounding.getWidth() + 2 * shadowness;
dHeight=Math.max(dHeight,titleBounding.getHeight() + 2 * shadowness);
break;
}
}
if (rtc != null) {
List<LegendItemHints> legendItems=legendData.legendItems;
LegendItemHints[] liha=legendItems.toArray(new LegendItemHints[legendItems.size()]);
LegendLayoutHints lilh=new LegendLayoutHints(SizeImpl.create(dWidth,dHeight),titleSize,legendData.bMinSliceApplied,legendData.sMinSliceLabel,liha);
rtc.setLegendLayoutHints(lilh);
}
sz=SizeImpl.create(dWidth,dHeight);
return sz;
}