Program: 76366
Project: 76366
Buggy source:
private double[] computeHorizalByLeftRightValue(IDisplayServer xs,Chart cm,SeriesDefinition[] seda,RunTimeContext rtc,ITextMetrics itm,Label la,LegendData legendData) throws ChartException {
  double dWidth=0, dHeight=0;
  double dMaxH=0, dRowHeight;
  double dRealWidth=0, dExtraHeight=0, dDeltaWidth;
  ArrayList columnList=new ArrayList();
  double dSeparatorThickness=legendData.dSeparatorThickness + legendData.dHorizontalSpacing;
  for (int j=0; j < seda.length; j++) {
    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);
      }
      double 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));
    }
    dRowHeight=dMaxH + legendData.dVerticalReservedSpace;
    if (dExtraHeight + dRowHeight > legendData.dAvailableHeight + legendData.dSafeSpacing) {
      dMaxH=-legendData.dVerticalReservedSpace;
    }
 else {
      legendData.legendItems.addAll(columnList);
      if (oneVisibleSerie && j < seda.length - 1 && (cm.getLegend().getSeparator() == null || cm.getLegend().getSeparator().isVisible())) {
        dWidth+=dSeparatorThickness;
        legendData.legendItems.add(new LegendItemHints(LEGEND_SEPERATOR,new Point(dWidth - dSeparatorThickness / 2,dExtraHeight),0,dMaxH + legendData.insCa.getTop() + legendData.insCa.getBottom(),null,0,null));
      }
    }
    columnList.clear();
  }
  dHeight+=legendData.dVerticalReservedSpace + dMaxH + dExtraHeight;
  dWidth=Math.max(dRealWidth,dWidth);
  return new double[]{dWidth,dHeight};
}

Fixed version (ground truth):
private double[] computeHorizalByLeftRightValue(IDisplayServer xs,Chart cm,SeriesDefinition[] seda,RunTimeContext rtc,ITextMetrics itm,Label la,LegendData legendData) throws ChartException {
  double dWidth=0, dHeight=0;
  double dMaxH=0, dRowHeight;
  double dRealWidth=0, dExtraHeight=0, dDeltaWidth;
  ArrayList columnList=new ArrayList();
  double dSeparatorThickness=legendData.dSeparatorThickness + legendData.dHorizontalSpacing;
  for (int j=0; j < seda.length; j++) {
    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);
      }
      double 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 (!isValidValue(obj) && 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));
    }
    dRowHeight=dMaxH + legendData.dVerticalReservedSpace;
    if (dExtraHeight + dRowHeight > legendData.dAvailableHeight + legendData.dSafeSpacing) {
      dMaxH=-legendData.dVerticalReservedSpace;
    }
 else {
      legendData.legendItems.addAll(columnList);
      if (oneVisibleSerie && j < seda.length - 1 && (cm.getLegend().getSeparator() == null || cm.getLegend().getSeparator().isVisible())) {
        dWidth+=dSeparatorThickness;
        legendData.legendItems.add(new LegendItemHints(LEGEND_SEPERATOR,new Point(dWidth - dSeparatorThickness / 2,dExtraHeight),0,dMaxH + legendData.insCa.getTop() + legendData.insCa.getBottom(),null,0,null));
      }
    }
    columnList.clear();
  }
  dHeight+=legendData.dVerticalReservedSpace + dMaxH + dExtraHeight;
  dWidth=Math.max(dRealWidth,dWidth);
  return new double[]{dWidth,dHeight};
}