Program: 76365
Project: 76365
Buggy source:
private double[] computeVerticalByTopBottomValue(IDisplayServer xs,Chart cm,SeriesDefinition[] seda,RunTimeContext rtc,ITextMetrics itm,Label la,LegendData legendData) throws ChartException {
  double dWidth=0, dHeight=0;
  double dW, dMaxW=0, dColumnWidth;
  double dRealHeight=0, dExtraWidth=0, dDeltaHeight;
  ArrayList columnList=new ArrayList();
  double dSeparatorThickness=legendData.dSeparatorThickness + legendData.dVerticalSpacing;
  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);
      }
      dW=bb.getWidth();
      double dFHeight=bb.getHeight();
      double dExtraHeight=0;
      String extraText=null;
      double dExceedingSpace=dExtraWidth + dW + legendData.dHorizonalReservedSpace - legendData.dAvailableWidth - legendData.dSafeSpacing;
      double[] newMetrics=checkEllipsisText(dExceedingSpace,dW,xs,itm,la,legendData.dEllipsisWidth,legendData.maxWrappingSize);
      if (newMetrics != null) {
        dW=newMetrics[0];
        dFHeight=newMetrics[1];
      }
      dDeltaHeight=legendData.insCa.getTop() + dFHeight + legendData.insCa.getBottom();
      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);
          BoundingBox bbV=null;
          try {
            bbV=Methods.computeBox(xs,IConstants.ABOVE,seLabel,0,0);
          }
 catch (          IllegalArgumentException uiex) {
            throw new ChartException(ChartEnginePlugin.ID,ChartException.RENDERING,uiex);
          }
          double dWV=bbV.getWidth();
          double dFHeightV=bbV.getHeight();
          double dExceedingSpaceV=dExtraWidth + dWV + legendData.dHorizonalReservedSpace - legendData.dAvailableWidth - legendData.dSafeSpacing;
          newMetrics=checkEllipsisText(dExceedingSpaceV,dWV,xs,itm,seLabel,legendData.dEllipsisWidth,legendData.maxWrappingSize);
          if (newMetrics != null) {
            dW=newMetrics[0];
            dFHeightV=newMetrics[1];
          }
          dW=Math.max(dW,itm.getFullWidth());
          dExtraHeight=Math.max(itm.getFullHeight(),dFHeightV);
          extraText=seLabel.getCaption().getValue();
          dDeltaHeight+=dExtraHeight + 2 * legendData.dScale;
        }
      }
      if (dHeight + dDeltaHeight > legendData.dAvailableHeight) {
        dColumnWidth=dMaxW + legendData.dHorizonalReservedSpace;
        if (dExtraWidth + dColumnWidth > legendData.dAvailableWidth + legendData.dSafeSpacing) {
          dMaxW=-legendData.dHorizonalReservedSpace;
          columnList.clear();
          break;
        }
 else {
          legendData.legendItems.addAll(columnList);
          columnList.clear();
          dExtraWidth+=dColumnWidth;
          dExceedingSpace=dExtraWidth + dW + legendData.dHorizonalReservedSpace - legendData.dAvailableWidth - legendData.dSafeSpacing;
          newMetrics=checkEllipsisText(dExceedingSpace,dW,xs,itm,la,legendData.dEllipsisWidth,legendData.maxWrappingSize);
          if (newMetrics != null) {
            dW=newMetrics[0];
            dFHeight=newMetrics[1];
            dDeltaHeight=legendData.insCa.getTop() + dFHeight + legendData.insCa.getBottom();
          }
          dMaxW=dW;
          dRealHeight=Math.max(dRealHeight,dHeight);
          dHeight=dDeltaHeight;
        }
      }
 else {
        dMaxW=Math.max(dW,dMaxW);
        dHeight+=dDeltaHeight;
      }
      columnList.add(new LegendItemHints(LEGEND_ENTRY,new Point(dExtraWidth,dHeight - dDeltaHeight),dW,dFHeight,la.getCaption().getValue(),dExtraHeight,extraText));
    }
    dColumnWidth=dMaxW + legendData.dHorizonalReservedSpace;
    if (dExtraWidth + dColumnWidth > legendData.dAvailableWidth + legendData.dSafeSpacing) {
      dMaxW=-legendData.dHorizonalReservedSpace;
    }
 else {
      legendData.legendItems.addAll(columnList);
      if (oneVisibleSerie && j < seda.length - 1 && (cm.getLegend().getSeparator() == null || cm.getLegend().getSeparator().isVisible())) {
        dHeight+=dSeparatorThickness;
        legendData.legendItems.add(new LegendItemHints(LEGEND_SEPERATOR,new Point(dExtraWidth,dHeight - dSeparatorThickness / 2),dMaxW + legendData.insCa.getLeft() + legendData.insCa.getRight()+ (3 * legendData.dItemHeight) / 2,0,null,0,null));
      }
    }
    columnList.clear();
  }
  dWidth=dMaxW + legendData.dHorizonalReservedSpace + dExtraWidth;
  dHeight=Math.max(dRealHeight,dHeight);
  return new double[]{dWidth,dHeight};
}

Fixed version (ground truth):
private double[] computeVerticalByTopBottomValue(IDisplayServer xs,Chart cm,SeriesDefinition[] seda,RunTimeContext rtc,ITextMetrics itm,Label la,LegendData legendData) throws ChartException {
  double dWidth=0, dHeight=0;
  double dW, dMaxW=0, dColumnWidth;
  double dRealHeight=0, dExtraWidth=0, dDeltaHeight;
  ArrayList columnList=new ArrayList();
  double dSeparatorThickness=legendData.dSeparatorThickness + legendData.dVerticalSpacing;
  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);
      }
      dW=bb.getWidth();
      double dFHeight=bb.getHeight();
      double dExtraHeight=0;
      String extraText=null;
      double dExceedingSpace=dExtraWidth + dW + legendData.dHorizonalReservedSpace - legendData.dAvailableWidth - legendData.dSafeSpacing;
      double[] newMetrics=checkEllipsisText(dExceedingSpace,dW,xs,itm,la,legendData.dEllipsisWidth,legendData.maxWrappingSize);
      if (newMetrics != null) {
        dW=newMetrics[0];
        dFHeight=newMetrics[1];
      }
      dDeltaHeight=legendData.insCa.getTop() + dFHeight + legendData.insCa.getBottom();
      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);
          BoundingBox bbV=null;
          try {
            bbV=Methods.computeBox(xs,IConstants.ABOVE,seLabel,0,0);
          }
 catch (          IllegalArgumentException uiex) {
            throw new ChartException(ChartEnginePlugin.ID,ChartException.RENDERING,uiex);
          }
          double dWV=bbV.getWidth();
          double dFHeightV=bbV.getHeight();
          double dExceedingSpaceV=dExtraWidth + dWV + legendData.dHorizonalReservedSpace - legendData.dAvailableWidth - legendData.dSafeSpacing;
          newMetrics=checkEllipsisText(dExceedingSpaceV,dWV,xs,itm,seLabel,legendData.dEllipsisWidth,legendData.maxWrappingSize);
          if (newMetrics != null) {
            dW=newMetrics[0];
            dFHeightV=newMetrics[1];
          }
          dW=Math.max(dW,itm.getFullWidth());
          dExtraHeight=Math.max(itm.getFullHeight(),dFHeightV);
          extraText=seLabel.getCaption().getValue();
          dDeltaHeight+=dExtraHeight + 2 * legendData.dScale;
        }
      }
      if (dHeight + dDeltaHeight > legendData.dAvailableHeight) {
        dColumnWidth=dMaxW + legendData.dHorizonalReservedSpace;
        if (dExtraWidth + dColumnWidth > legendData.dAvailableWidth + legendData.dSafeSpacing) {
          dMaxW=-legendData.dHorizonalReservedSpace;
          columnList.clear();
          break;
        }
 else {
          legendData.legendItems.addAll(columnList);
          columnList.clear();
          dExtraWidth+=dColumnWidth;
          dExceedingSpace=dExtraWidth + dW + legendData.dHorizonalReservedSpace - legendData.dAvailableWidth - legendData.dSafeSpacing;
          newMetrics=checkEllipsisText(dExceedingSpace,dW,xs,itm,la,legendData.dEllipsisWidth,legendData.maxWrappingSize);
          if (newMetrics != null) {
            dW=newMetrics[0];
            dFHeight=newMetrics[1];
            dDeltaHeight=legendData.insCa.getTop() + dFHeight + legendData.insCa.getBottom();
          }
          dMaxW=dW;
          dRealHeight=Math.max(dRealHeight,dHeight);
          dHeight=dDeltaHeight;
        }
      }
 else {
        dMaxW=Math.max(dW,dMaxW);
        dHeight+=dDeltaHeight;
      }
      columnList.add(new LegendItemHints(LEGEND_ENTRY,new Point(dExtraWidth,dHeight - dDeltaHeight),dW,dFHeight,la.getCaption().getValue(),dExtraHeight,extraText));
    }
    dColumnWidth=dMaxW + legendData.dHorizonalReservedSpace;
    if (dExtraWidth + dColumnWidth > legendData.dAvailableWidth + legendData.dSafeSpacing) {
      dMaxW=-legendData.dHorizonalReservedSpace;
    }
 else {
      legendData.legendItems.addAll(columnList);
      if (oneVisibleSerie && j < seda.length - 1 && (cm.getLegend().getSeparator() == null || cm.getLegend().getSeparator().isVisible())) {
        dHeight+=dSeparatorThickness;
        legendData.legendItems.add(new LegendItemHints(LEGEND_SEPERATOR,new Point(dExtraWidth,dHeight - dSeparatorThickness / 2),dMaxW + legendData.insCa.getLeft() + legendData.insCa.getRight()+ (3 * legendData.dItemHeight) / 2,0,null,0,null));
      }
    }
    columnList.clear();
  }
  dWidth=dMaxW + legendData.dHorizonalReservedSpace + dExtraWidth;
  dHeight=Math.max(dRealHeight,dHeight);
  return new double[]{dWidth,dHeight};
}