Program: 75829
Project: 75829
Buggy source:
private double[] computeVerticalByCategory(IDisplayServer xs,Chart cm,RunTimeContext rtc,ITextMetrics itm,Label la,LegendData legendData) throws ChartException {
  double dWidth=0, dHeight=0;
  double dColumnWidth;
  double dRealHeight=0, dExtraWidth=0, dDeltaHeight;
  ArrayList columnList=new ArrayList();
  SeriesDefinition sdBase=null;
  if (cm instanceof ChartWithAxes) {
    final Axis axPrimaryBase=((ChartWithAxes)cm).getBaseAxes()[0];
    if (axPrimaryBase.getSeriesDefinitions().isEmpty()) {
      return null;
    }
    sdBase=(SeriesDefinition)axPrimaryBase.getSeriesDefinitions().get(0);
  }
 else   if (cm instanceof ChartWithoutAxes) {
    if (((ChartWithoutAxes)cm).getSeriesDefinitions().isEmpty()) {
      return null;
    }
    sdBase=(SeriesDefinition)((ChartWithoutAxes)cm).getSeriesDefinitions().get(0);
  }
  Series seBase=(Series)sdBase.getRunTimeSeries().get(0);
  DataSetIterator dsiBase=null;
  try {
    dsiBase=new DataSetIterator(seBase.getDataSet());
  }
 catch (  Exception ex) {
    throw new ChartException(ChartEnginePlugin.ID,ChartException.GENERATION,ex);
  }
  FormatSpecifier fs=null;
  if (sdBase != null) {
    fs=sdBase.getFormatSpecifier();
  }
  int pos=-1;
  while (dsiBase.hasNext()) {
    Object obj=dsiBase.next();
    obj=getNonNullValue(obj,IConstants.ONE_SPACE);
    while (!isValidValue(obj) && dsiBase.hasNext()) {
      obj=dsiBase.next();
    }
    pos++;
    if (legendData.bMinSliceApplied && Arrays.binarySearch(legendData.filteredMinSliceEntry,pos) >= 0) {
      continue;
    }
    String lgtext=String.valueOf(obj);
    if (fs != null) {
      try {
        lgtext=ValueFormatter.format(obj,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 dFWidth=bb.getWidth();
    double dFHeight=bb.getHeight();
    double dExceedingSpace=dExtraWidth + dFWidth + legendData.dHorizonalReservedSpace - legendData.dAvailableWidth - legendData.dSafeSpacing;
    double[] newMetrics=checkEllipsisText(dExceedingSpace,dFWidth,xs,itm,la,legendData.dEllipsisWidth,legendData.maxWrappingSize);
    if (newMetrics != null) {
      dFWidth=newMetrics[0];
      dFHeight=newMetrics[1];
    }
    dDeltaHeight=legendData.insCa.getTop() + dFHeight + legendData.insCa.getBottom();
    if (dHeight + dDeltaHeight > legendData.dAvailableHeight) {
      dColumnWidth=dWidth + legendData.dHorizonalReservedSpace;
      if (dExtraWidth + dColumnWidth > legendData.dAvailableWidth + legendData.dSafeSpacing) {
        dWidth=-legendData.dHorizonalReservedSpace;
        columnList.clear();
        break;
      }
 else {
        legendData.legendItems.addAll(columnList);
        columnList.clear();
        dExtraWidth+=dColumnWidth;
        dExceedingSpace=dExtraWidth + dFWidth + legendData.dHorizonalReservedSpace - legendData.dAvailableWidth - legendData.dSafeSpacing;
        newMetrics=checkEllipsisText(dExceedingSpace,dFWidth,xs,itm,la,legendData.dEllipsisWidth,legendData.maxWrappingSize);
        if (newMetrics != null) {
          dFWidth=newMetrics[0];
          dFHeight=newMetrics[1];
          dDeltaHeight=legendData.insCa.getTop() + dFHeight + legendData.insCa.getBottom();
        }
        dWidth=dFWidth;
        dRealHeight=Math.max(dRealHeight,dHeight);
        dHeight=dDeltaHeight;
      }
    }
 else {
      dWidth=Math.max(dFWidth,dWidth);
      dHeight+=dDeltaHeight;
    }
    columnList.add(new LegendItemHints(LEGEND_ENTRY,new Point(dExtraWidth,dHeight - dDeltaHeight),dFWidth,dFHeight,la.getCaption().getValue(),pos));
  }
  if (legendData.bMinSliceApplied) {
    la.getCaption().setValue(legendData.sMinSliceLabel);
    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 dFWidth=bb.getWidth();
    double dFHeight=bb.getHeight();
    double dExceedingSpace=dExtraWidth + dFWidth + legendData.dHorizonalReservedSpace - legendData.dAvailableWidth - legendData.dSafeSpacing;
    double[] newMetrics=checkEllipsisText(dExceedingSpace,dFWidth,xs,itm,la,legendData.dEllipsisWidth,legendData.maxWrappingSize);
    if (newMetrics != null) {
      dFWidth=newMetrics[0];
      dFHeight=newMetrics[1];
    }
    dDeltaHeight=legendData.insCa.getTop() + dFHeight + legendData.insCa.getBottom();
    if (dHeight + dDeltaHeight > legendData.dAvailableHeight) {
      dColumnWidth=dWidth + legendData.dHorizonalReservedSpace;
      if (dExtraWidth + dColumnWidth > legendData.dAvailableWidth + legendData.dSafeSpacing) {
        dWidth=-legendData.dHorizonalReservedSpace;
        columnList.clear();
      }
 else {
        legendData.legendItems.addAll(columnList);
        columnList.clear();
        dExtraWidth+=dColumnWidth;
        dExceedingSpace=dExtraWidth + dFWidth + legendData.dHorizonalReservedSpace - legendData.dAvailableWidth - legendData.dSafeSpacing;
        newMetrics=checkEllipsisText(dExceedingSpace,dFWidth,xs,itm,la,legendData.dEllipsisWidth,legendData.maxWrappingSize);
        if (newMetrics != null) {
          dFWidth=newMetrics[0];
          dFHeight=newMetrics[1];
          dDeltaHeight=legendData.insCa.getTop() + dFHeight + legendData.insCa.getBottom();
        }
        dWidth=dFWidth;
        dRealHeight=Math.max(dRealHeight,dHeight);
        dHeight=dDeltaHeight;
        columnList.add(new LegendItemHints(LEGEND_MINSLICE_ENTRY,new Point(dExtraWidth,dHeight - dDeltaHeight),dFWidth,dFHeight,la.getCaption().getValue(),dsiBase.size()));
      }
    }
 else {
      dWidth=Math.max(dFWidth,dWidth);
      dHeight+=dDeltaHeight;
      columnList.add(new LegendItemHints(LEGEND_MINSLICE_ENTRY,new Point(dExtraWidth,dHeight - dDeltaHeight),dFWidth,dFHeight,la.getCaption().getValue(),dsiBase.size()));
    }
  }
  dColumnWidth=dWidth + legendData.dHorizonalReservedSpace;
  if (dExtraWidth + dColumnWidth > legendData.dAvailableWidth + legendData.dSafeSpacing) {
    dWidth=-legendData.dHorizonalReservedSpace;
  }
 else {
    legendData.legendItems.addAll(columnList);
  }
  columnList.clear();
  dWidth+=legendData.dHorizonalReservedSpace + dExtraWidth;
  dHeight=Math.max(dRealHeight,dHeight);
  return new double[]{dWidth,dHeight};
}

Fixed version (ground truth):
private double[] computeVerticalByCategory(IDisplayServer xs,Chart cm,RunTimeContext rtc,ITextMetrics itm,Label la,LegendData legendData) throws ChartException {
  double dWidth=0, dHeight=0;
  double dColumnWidth;
  double dRealHeight=0, dExtraWidth=0, dDeltaHeight;
  ArrayList columnList=new ArrayList();
  SeriesDefinition sdBase=null;
  if (cm instanceof ChartWithAxes) {
    final Axis axPrimaryBase=((ChartWithAxes)cm).getBaseAxes()[0];
    if (axPrimaryBase.getSeriesDefinitions().isEmpty()) {
      return null;
    }
    sdBase=(SeriesDefinition)axPrimaryBase.getSeriesDefinitions().get(0);
  }
 else   if (cm instanceof ChartWithoutAxes) {
    if (((ChartWithoutAxes)cm).getSeriesDefinitions().isEmpty()) {
      return null;
    }
    sdBase=(SeriesDefinition)((ChartWithoutAxes)cm).getSeriesDefinitions().get(0);
  }
  Series seBase=(Series)sdBase.getRunTimeSeries().get(0);
  DataSetIterator dsiBase=null;
  try {
    dsiBase=new DataSetIterator(seBase.getDataSet());
  }
 catch (  Exception ex) {
    throw new ChartException(ChartEnginePlugin.ID,ChartException.GENERATION,ex);
  }
  FormatSpecifier fs=null;
  if (sdBase != null) {
    fs=sdBase.getFormatSpecifier();
  }
  int pos=-1;
  while (dsiBase.hasNext()) {
    Object obj=dsiBase.next();
    obj=getNonEmptyValue(obj,IConstants.ONE_SPACE);
    while (!isValidValue(obj) && dsiBase.hasNext()) {
      obj=dsiBase.next();
    }
    pos++;
    if (legendData.bMinSliceApplied && Arrays.binarySearch(legendData.filteredMinSliceEntry,pos) >= 0) {
      continue;
    }
    String lgtext=String.valueOf(obj);
    if (fs != null) {
      try {
        lgtext=ValueFormatter.format(obj,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 dFWidth=bb.getWidth();
    double dFHeight=bb.getHeight();
    double dExceedingSpace=dExtraWidth + dFWidth + legendData.dHorizonalReservedSpace - legendData.dAvailableWidth - legendData.dSafeSpacing;
    double[] newMetrics=checkEllipsisText(dExceedingSpace,dFWidth,xs,itm,la,legendData.dEllipsisWidth,legendData.maxWrappingSize);
    if (newMetrics != null) {
      dFWidth=newMetrics[0];
      dFHeight=newMetrics[1];
    }
    dDeltaHeight=legendData.insCa.getTop() + dFHeight + legendData.insCa.getBottom();
    if (dHeight + dDeltaHeight > legendData.dAvailableHeight) {
      dColumnWidth=dWidth + legendData.dHorizonalReservedSpace;
      if (dExtraWidth + dColumnWidth > legendData.dAvailableWidth + legendData.dSafeSpacing) {
        dWidth=-legendData.dHorizonalReservedSpace;
        columnList.clear();
        break;
      }
 else {
        legendData.legendItems.addAll(columnList);
        columnList.clear();
        dExtraWidth+=dColumnWidth;
        dExceedingSpace=dExtraWidth + dFWidth + legendData.dHorizonalReservedSpace - legendData.dAvailableWidth - legendData.dSafeSpacing;
        newMetrics=checkEllipsisText(dExceedingSpace,dFWidth,xs,itm,la,legendData.dEllipsisWidth,legendData.maxWrappingSize);
        if (newMetrics != null) {
          dFWidth=newMetrics[0];
          dFHeight=newMetrics[1];
          dDeltaHeight=legendData.insCa.getTop() + dFHeight + legendData.insCa.getBottom();
        }
        dWidth=dFWidth;
        dRealHeight=Math.max(dRealHeight,dHeight);
        dHeight=dDeltaHeight;
      }
    }
 else {
      dWidth=Math.max(dFWidth,dWidth);
      dHeight+=dDeltaHeight;
    }
    columnList.add(new LegendItemHints(LEGEND_ENTRY,new Point(dExtraWidth,dHeight - dDeltaHeight),dFWidth,dFHeight,la.getCaption().getValue(),pos));
  }
  if (legendData.bMinSliceApplied) {
    la.getCaption().setValue(legendData.sMinSliceLabel);
    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 dFWidth=bb.getWidth();
    double dFHeight=bb.getHeight();
    double dExceedingSpace=dExtraWidth + dFWidth + legendData.dHorizonalReservedSpace - legendData.dAvailableWidth - legendData.dSafeSpacing;
    double[] newMetrics=checkEllipsisText(dExceedingSpace,dFWidth,xs,itm,la,legendData.dEllipsisWidth,legendData.maxWrappingSize);
    if (newMetrics != null) {
      dFWidth=newMetrics[0];
      dFHeight=newMetrics[1];
    }
    dDeltaHeight=legendData.insCa.getTop() + dFHeight + legendData.insCa.getBottom();
    if (dHeight + dDeltaHeight > legendData.dAvailableHeight) {
      dColumnWidth=dWidth + legendData.dHorizonalReservedSpace;
      if (dExtraWidth + dColumnWidth > legendData.dAvailableWidth + legendData.dSafeSpacing) {
        dWidth=-legendData.dHorizonalReservedSpace;
        columnList.clear();
      }
 else {
        legendData.legendItems.addAll(columnList);
        columnList.clear();
        dExtraWidth+=dColumnWidth;
        dExceedingSpace=dExtraWidth + dFWidth + legendData.dHorizonalReservedSpace - legendData.dAvailableWidth - legendData.dSafeSpacing;
        newMetrics=checkEllipsisText(dExceedingSpace,dFWidth,xs,itm,la,legendData.dEllipsisWidth,legendData.maxWrappingSize);
        if (newMetrics != null) {
          dFWidth=newMetrics[0];
          dFHeight=newMetrics[1];
          dDeltaHeight=legendData.insCa.getTop() + dFHeight + legendData.insCa.getBottom();
        }
        dWidth=dFWidth;
        dRealHeight=Math.max(dRealHeight,dHeight);
        dHeight=dDeltaHeight;
        columnList.add(new LegendItemHints(LEGEND_MINSLICE_ENTRY,new Point(dExtraWidth,dHeight - dDeltaHeight),dFWidth,dFHeight,la.getCaption().getValue(),dsiBase.size()));
      }
    }
 else {
      dWidth=Math.max(dFWidth,dWidth);
      dHeight+=dDeltaHeight;
      columnList.add(new LegendItemHints(LEGEND_MINSLICE_ENTRY,new Point(dExtraWidth,dHeight - dDeltaHeight),dFWidth,dFHeight,la.getCaption().getValue(),dsiBase.size()));
    }
  }
  dColumnWidth=dWidth + legendData.dHorizonalReservedSpace;
  if (dExtraWidth + dColumnWidth > legendData.dAvailableWidth + legendData.dSafeSpacing) {
    dWidth=-legendData.dHorizonalReservedSpace;
  }
 else {
    legendData.legendItems.addAll(columnList);
  }
  columnList.clear();
  dWidth+=legendData.dHorizonalReservedSpace + dExtraWidth;
  dHeight=Math.max(dRealHeight,dHeight);
  return new double[]{dWidth,dHeight};
}