Program: 76739
Project: 76739
Buggy source:
private double[] computeHorizalByTopBottomValue(IDisplayServer xs,Chart cm,SeriesDefinition[] seda,RunTimeContext rtc,ITextMetrics itm,Label la,LegendData legendData) throws ChartException {
  double dWidth=0, dHeight=0;
  double dH, dMaxH=0, dRowHeight;
  double dRealWidth=0, dExtraHeight=0, dDeltaWidth;
  ArrayList columnList=new ArrayList();
  legendData.dSeparatorThickness+=legendData.dVerticalSpacing;
  for (int j=0; j < seda.length; j++) {
    dWidth=0;
    List al=seda[j].getRunTimeSeries();
    FormatSpecifier fs=seda[j].getFormatSpecifier();
    boolean oneVisibleSerie=false;
    for (int i=0; i < al.size(); i++) {
      Series se=(Series)al.get(i);
      if (se.isVisible()) {
        oneVisibleSerie=true;
      }
 else {
        continue;
      }
      Object obj=se.getSeriesIdentifier();
      String lgtext=rtc.externalizedMessage(String.valueOf(obj));
      if (fs != null) {
        try {
          lgtext=ValueFormatter.format(lgtext,fs,rtc.getULocale(),null);
        }
 catch (        ChartException e) {
        }
      }
      la.getCaption().setValue(lgtext);
      itm.reuse(la,legendData.maxWrappingSize);
      BoundingBox bb=null;
      try {
        bb=Methods.computeBox(xs,IConstants.ABOVE,la,0,0);
      }
 catch (      IllegalArgumentException uiex) {
        throw new ChartException(ChartEnginePlugin.ID,ChartException.RENDERING,uiex);
      }
      dH=bb.getHeight();
      double dFHeight=dH;
      double dFWidth=bb.getWidth();
      double dEHeight=0;
      String extraText=null;
      dDeltaWidth=legendData.insCa.getLeft() + (3 * legendData.dItemHeight) / 2 + dFWidth + legendData.insCa.getRight() + legendData.dHorizontalSpacing;
      if (cm.getLegend().isShowValue()) {
        DataSetIterator dsiBase=null;
        try {
          dsiBase=new DataSetIterator(se.getDataSet());
        }
 catch (        Exception ex) {
          throw new ChartException(ChartEnginePlugin.ID,ChartException.GENERATION,ex);
        }
        if (dsiBase.hasNext()) {
          obj=dsiBase.next();
          while (obj == null && dsiBase.hasNext()) {
            obj=dsiBase.next();
          }
          String valueText=String.valueOf(obj);
          if (fs != null) {
            try {
              lgtext=ValueFormatter.format(obj,fs,rtc.getULocale(),null);
            }
 catch (            ChartException e) {
            }
          }
          Label seLabel=LabelImpl.copyInstance(se.getLabel());
          seLabel.getCaption().setValue(valueText);
          itm.reuse(seLabel);
          dEHeight=itm.getFullHeight();
          extraText=seLabel.getCaption().getValue();
          dH+=dEHeight + 2 * legendData.dScale;
          dDeltaWidth=Math.max(dDeltaWidth,itm.getFullWidth());
        }
      }
      if (dWidth + dDeltaWidth > legendData.dAvailableWidth) {
        dRowHeight=dMaxH + legendData.dVerticalReservedSpace;
        if (dExtraHeight + dRowHeight > legendData.dAvailableHeight + legendData.dSafeSpacing) {
          dMaxH=-legendData.dVerticalReservedSpace;
          columnList.clear();
          break;
        }
 else {
          legendData.legendItems.addAll(columnList);
          columnList.clear();
          dExtraHeight+=dRowHeight;
          dMaxH=dH;
          dRealWidth=Math.max(dRealWidth,dWidth);
          dWidth=dDeltaWidth;
        }
      }
 else {
        dMaxH=Math.max(dH,dMaxH);
        dWidth+=dDeltaWidth;
      }
      columnList.add(new LegendItemHints(LEGEND_ENTRY,new Point(dWidth - dDeltaWidth,dExtraHeight),dFWidth,dFHeight,la.getCaption().getValue(),dEHeight,extraText));
    }
    dRealWidth=Math.max(dRealWidth,dWidth);
    dRowHeight=dMaxH + legendData.dVerticalReservedSpace;
    if (dExtraHeight + dRowHeight > legendData.dAvailableHeight + legendData.dSafeSpacing) {
    }
 else {
      legendData.legendItems.addAll(columnList);
      if (oneVisibleSerie) {
        dExtraHeight+=dRowHeight;
        if (j < seda.length - 1 && (cm.getLegend().getSeparator() == null || cm.getLegend().getSeparator().isVisible())) {
          dHeight+=legendData.dSeparatorThickness;
          legendData.legendItems.add(new LegendItemHints(LEGEND_SEPERATOR,new Point(0,dExtraHeight - legendData.dSeparatorThickness / 2),dRealWidth,0,null,0,null));
        }
      }
    }
    columnList.clear();
    dMaxH=0;
    dWidth=0;
  }
  dHeight+=dExtraHeight;
  dWidth=Math.max(dRealWidth,dWidth);
  return new double[]{dHeight,dWidth};
}

Fixed version (ground truth):
private double[] computeHorizalByTopBottomValue(IDisplayServer xs,Chart cm,SeriesDefinition[] seda,RunTimeContext rtc,ITextMetrics itm,Label la,LegendData legendData) throws ChartException {
  double dWidth=0, dHeight=0;
  double dH, dMaxH=0, dRowHeight;
  double dRealWidth=0, dExtraHeight=0, dDeltaWidth;
  ArrayList columnList=new ArrayList();
  legendData.dSeparatorThickness+=legendData.dVerticalSpacing;
  for (int j=0; j < seda.length; j++) {
    dWidth=0;
    List al=seda[j].getRunTimeSeries();
    FormatSpecifier fs=seda[j].getFormatSpecifier();
    boolean oneVisibleSerie=false;
    for (int i=0; i < al.size(); i++) {
      Series se=(Series)al.get(i);
      if (se.isVisible()) {
        oneVisibleSerie=true;
      }
 else {
        continue;
      }
      Object obj=se.getSeriesIdentifier();
      String lgtext=rtc.externalizedMessage(String.valueOf(obj));
      if (fs != null) {
        try {
          lgtext=ValueFormatter.format(lgtext,fs,rtc.getULocale(),null);
        }
 catch (        ChartException e) {
        }
      }
      la.getCaption().setValue(lgtext);
      itm.reuse(la,legendData.maxWrappingSize);
      BoundingBox bb=null;
      try {
        bb=Methods.computeBox(xs,IConstants.ABOVE,la,0,0);
      }
 catch (      IllegalArgumentException uiex) {
        throw new ChartException(ChartEnginePlugin.ID,ChartException.RENDERING,uiex);
      }
      dH=bb.getHeight();
      double dFHeight=dH;
      double dFWidth=bb.getWidth();
      double dEHeight=0;
      String extraText=null;
      dDeltaWidth=legendData.insCa.getLeft() + (3 * legendData.dItemHeight) / 2 + dFWidth + legendData.insCa.getRight() + legendData.dHorizontalSpacing;
      if (cm.getLegend().isShowValue()) {
        DataSetIterator dsiBase=null;
        try {
          dsiBase=new DataSetIterator(se.getDataSet());
        }
 catch (        Exception ex) {
          throw new ChartException(ChartEnginePlugin.ID,ChartException.GENERATION,ex);
        }
        if (dsiBase.hasNext()) {
          obj=dsiBase.next();
          while (obj == null && dsiBase.hasNext()) {
            obj=dsiBase.next();
          }
          String valueText=String.valueOf(obj);
          if (fs != null) {
            try {
              lgtext=ValueFormatter.format(obj,fs,rtc.getULocale(),null);
            }
 catch (            ChartException e) {
            }
          }
          Label seLabel=LabelImpl.copyInstance(se.getLabel());
          seLabel.getCaption().setValue(valueText);
          itm.reuse(seLabel);
          dEHeight=itm.getFullHeight();
          extraText=seLabel.getCaption().getValue();
          dH+=dEHeight + 2 * legendData.dScale;
          dDeltaWidth=Math.max(dDeltaWidth,itm.getFullWidth());
        }
      }
      if (dWidth + dDeltaWidth > legendData.dAvailableWidth) {
        dRowHeight=dMaxH + legendData.dVerticalReservedSpace;
        if (dExtraHeight + dRowHeight > legendData.dAvailableHeight + legendData.dSafeSpacing) {
          dMaxH=-legendData.dVerticalReservedSpace;
          columnList.clear();
          break;
        }
 else {
          legendData.legendItems.addAll(columnList);
          columnList.clear();
          dExtraHeight+=dRowHeight;
          dMaxH=dH;
          dRealWidth=Math.max(dRealWidth,dWidth);
          dWidth=dDeltaWidth;
        }
      }
 else {
        dMaxH=Math.max(dH,dMaxH);
        dWidth+=dDeltaWidth;
      }
      columnList.add(new LegendItemHints(LEGEND_ENTRY,new Point(dWidth - dDeltaWidth,dExtraHeight),dFWidth,dFHeight,la.getCaption().getValue(),dEHeight,extraText));
    }
    dRealWidth=Math.max(dRealWidth,dWidth);
    dRowHeight=dMaxH + legendData.dVerticalReservedSpace;
    if (dExtraHeight + dRowHeight > legendData.dAvailableHeight + legendData.dSafeSpacing) {
    }
 else {
      legendData.legendItems.addAll(columnList);
      if (oneVisibleSerie) {
        dExtraHeight+=dRowHeight;
        if (j < seda.length - 1 && (cm.getLegend().getSeparator() == null || cm.getLegend().getSeparator().isVisible())) {
          dHeight+=legendData.dSeparatorThickness;
          legendData.legendItems.add(new LegendItemHints(LEGEND_SEPERATOR,new Point(0,dExtraHeight - legendData.dSeparatorThickness / 2),dRealWidth,0,null,0,null));
        }
      }
    }
    columnList.clear();
    dMaxH=0;
    dWidth=0;
  }
  dHeight+=dExtraHeight;
  dWidth=Math.max(dRealWidth,dWidth);
  return new double[]{dWidth,dHeight};
}