Program: 76361
Project: 76361
Buggy source:
private double[] computeVerticalByLeftRightValue(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.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);
      }
      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);
          dW=Math.max(dW,itm.getFullWidth());
          dExtraHeight=itm.getFullHeight();
          extraText=seLabel.getCaption().getValue();
          dDeltaHeight+=itm.getFullHeight() + 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));
    }
    dRealHeight=Math.max(dRealHeight,dHeight);
    dColumnWidth=dMaxW + legendData.dHorizonalReservedSpace;
    if (dExtraWidth + dColumnWidth > legendData.dAvailableWidth + legendData.dSafeSpacing) {
    }
 else {
      legendData.legendItems.addAll(columnList);
      if (oneVisibleSerie) {
        dExtraWidth+=dMaxW + legendData.dHorizonalReservedSpace;
        if (j < seda.length - 1 && (cm.getLegend().getSeparator() == null || cm.getLegend().getSeparator().isVisible())) {
          dExtraWidth+=dSeparatorThickness;
          legendData.legendItems.add(new LegendItemHints(LEGEND_SEPERATOR,new Point(dExtraWidth - dSeparatorThickness / 2,0),0,dRealHeight,null,0,null));
        }
      }
    }
    columnList.clear();
    dMaxW=0;
    dHeight=0;
  }
  dWidth+=dExtraWidth;
  dHeight=Math.max(dRealHeight,dHeight);
  return new double[]{dWidth,dHeight};
}

Fixed version (ground truth):
private double[] computeVerticalByLeftRightValue(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.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);
      }
      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);
          dW=Math.max(dW,itm.getFullWidth());
          dExtraHeight=itm.getFullHeight();
          extraText=seLabel.getCaption().getValue();
          dDeltaHeight+=itm.getFullHeight() + 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));
    }
    dRealHeight=Math.max(dRealHeight,dHeight);
    dColumnWidth=dMaxW + legendData.dHorizonalReservedSpace;
    if (dExtraWidth + dColumnWidth > legendData.dAvailableWidth + legendData.dSafeSpacing) {
    }
 else {
      legendData.legendItems.addAll(columnList);
      if (oneVisibleSerie) {
        dExtraWidth+=dMaxW + legendData.dHorizonalReservedSpace;
        if (j < seda.length - 1 && (cm.getLegend().getSeparator() == null || cm.getLegend().getSeparator().isVisible())) {
          dExtraWidth+=dSeparatorThickness;
          legendData.legendItems.add(new LegendItemHints(LEGEND_SEPERATOR,new Point(dExtraWidth - dSeparatorThickness / 2,0),0,dRealHeight,null,0,null));
        }
      }
    }
    columnList.clear();
    dMaxW=0;
    dHeight=0;
  }
  dWidth+=dExtraWidth;
  dHeight=Math.max(dRealHeight,dHeight);
  return new double[]{dWidth,dHeight};
}