Program: 71361
Project: 71361
Buggy source:
/** 
 * Checks all labels for any overlap for a given axis' scale
 * @param la
 * @param iLabelLocation
 * @return
 */
public final boolean checkFit(IDisplayServer xs,Label la,int iLabelLocation) throws ChartException {
  if (isCategoryScale()) {
    return true;
  }
  final double dAngleInDegrees=la.getCaption().getFont().getRotation();
  double x=0, y=0;
  int iPointToCheck=0;
  if (iLabelLocation == ABOVE || iLabelLocation == BELOW) {
    if (iScaleDirection == BACKWARD) {
      iPointToCheck=(dAngleInDegrees < 0 && dAngleInDegrees > -90) ? 1 : 2;
    }
 else {
      iPointToCheck=(dAngleInDegrees < 0 && dAngleInDegrees > -90) ? 3 : 0;
    }
  }
 else   if (iLabelLocation == LEFT || iLabelLocation == RIGHT) {
    if (iScaleDirection == FORWARD) {
      iPointToCheck=(dAngleInDegrees < 0 && dAngleInDegrees > -90) ? 0 : 1;
    }
 else {
      iPointToCheck=(dAngleInDegrees < 0 && dAngleInDegrees > -90) ? 2 : 3;
    }
  }
  AxisTickCoordinates da=atcTickCoordinates;
  RotatedRectangle rrPrev=null, rrPrev2=null, rr;
  Double fontHeight=Methods.computeFontHeight(xs,la);
  if ((iType & (NUMERICAL | LINEAR)) == (NUMERICAL | LINEAR)) {
    double dAxisValue=asDouble(getMinimum()).doubleValue();
    final double dAxisStep=asDouble(getStep()).doubleValue();
    String sText;
    DecimalFormat df=null;
    if (fs == null) {
      df=computeDecimalFormat(dAxisValue,dAxisStep);
    }
    final NumberDataElement nde=NumberDataElementImpl.create(0);
    for (int i=0; i < da.size(); i++) {
      nde.setValue(dAxisValue);
      try {
        sText=ValueFormatter.format(nde,fs,rtc.getULocale(),df);
      }
 catch (      ChartException dfex) {
        logger.log(dfex);
        sText=NULL_STRING;
      }
      if (iLabelLocation == ABOVE || iLabelLocation == BELOW) {
        x=da.getCoordinate(i) * dZoomFactor;
      }
 else       if (iLabelLocation == LEFT || iLabelLocation == RIGHT) {
        y=da.getCoordinate(i) * dZoomFactor;
      }
      la.getCaption().setValue(sText);
      try {
        rr=computePolygon(xs,iLabelLocation,la,x,y,fontHeight);
      }
 catch (      IllegalArgumentException uiex) {
        throw new ChartException(ChartEnginePlugin.ID,ChartException.GENERATION,uiex);
      }
      Point p=rr.getPoint(iPointToCheck);
      if (isAxisLabelStaggered() && isTickLabelStaggered(i)) {
        if (rrPrev2 != null && (rrPrev2.contains(p) || rrPrev2.getPoint(iPointToCheck).equals(p) || ChartUtil.intersects(rr,rrPrev2))) {
          return false;
        }
        rrPrev2=rr;
      }
 else {
        if (rrPrev != null && (rrPrev.contains(p) || rrPrev.getPoint(iPointToCheck).equals(p) || ChartUtil.intersects(rr,rrPrev))) {
          return false;
        }
        rrPrev=rr;
      }
      dAxisValue+=dAxisStep;
    }
  }
 else   if ((iType & (NUMERICAL | LOGARITHMIC)) == (NUMERICAL | LOGARITHMIC)) {
    double dAxisValue=asDouble(getMinimum()).doubleValue();
    final double dAxisStep=asDouble(getStep()).doubleValue();
    String sText;
    NumberDataElement nde=NumberDataElementImpl.create(0);
    DecimalFormat df=null;
    for (int i=0; i < da.size() - 1; i++) {
      nde.setValue(dAxisValue);
      if (fs == null) {
        df=computeDecimalFormat(dAxisValue,dAxisStep);
      }
      try {
        sText=ValueFormatter.format(nde,fs,rtc.getULocale(),df);
      }
 catch (      ChartException dfex) {
        logger.log(dfex);
        sText=NULL_STRING;
      }
      if (iLabelLocation == ABOVE || iLabelLocation == BELOW) {
        x=da.getCoordinate(i) * dZoomFactor;
      }
 else       if (iLabelLocation == LEFT || iLabelLocation == RIGHT) {
        y=da.getCoordinate(i) * dZoomFactor;
      }
      la.getCaption().setValue(sText);
      try {
        rr=computePolygon(xs,iLabelLocation,la,x,y,fontHeight);
      }
 catch (      IllegalArgumentException uiex) {
        throw new ChartException(ChartEnginePlugin.ID,ChartException.GENERATION,uiex);
      }
      Point p=rr.getPoint(iPointToCheck);
      if (isAxisLabelStaggered() && isTickLabelStaggered(i)) {
        if (rrPrev2 != null && (rrPrev2.contains(p) || rrPrev2.getPoint(iPointToCheck).equals(p) || ChartUtil.intersects(rr,rrPrev2))) {
          return false;
        }
        rrPrev2=rr;
      }
 else {
        if (rrPrev != null && (rrPrev.contains(p) || rrPrev.getPoint(iPointToCheck).equals(p))) {
          return false;
        }
        rrPrev=rr;
      }
      dAxisValue*=dAxisStep;
    }
  }
 else   if (iType == DATE_TIME) {
    CDateTime cdt, cdtAxisValue=asDateTime(oMinimum);
    final int iUnit=asInteger(oUnit);
    final int iStep=asInteger(oStep);
    final IDateFormatWrapper sdf=DateFormatWrapperFactory.getPreferredDateFormat(iUnit,rtc.getULocale());
    String sText;
    cdt=cdtAxisValue;
    for (int i=0; i < da.size() - 1; i++) {
      sText=ValueFormatter.format(cdt,fs,rtc.getULocale(),sdf);
      if (iLabelLocation == ABOVE || iLabelLocation == BELOW) {
        x=da.getCoordinate(i) * dZoomFactor;
      }
 else       if (iLabelLocation == LEFT || iLabelLocation == RIGHT) {
        y=da.getCoordinate(i) * dZoomFactor;
      }
      la.getCaption().setValue(sText);
      try {
        rr=computePolygon(xs,iLabelLocation,la,x,y,fontHeight);
      }
 catch (      IllegalArgumentException uiex) {
        throw new ChartException(ChartEnginePlugin.ID,ChartException.GENERATION,uiex);
      }
      Point p=rr.getPoint(iPointToCheck);
      if (isAxisLabelStaggered() && isTickLabelStaggered(i)) {
        if (rrPrev2 != null && (rrPrev2.contains(p) || rrPrev2.getPoint(iPointToCheck).equals(p) || ChartUtil.intersects(rr,rrPrev2))) {
          return false;
        }
        rrPrev2=rr;
      }
 else {
        if (rrPrev != null && (rrPrev.contains(p) || rrPrev.getPoint(iPointToCheck).equals(p))) {
          return false;
        }
        rrPrev=rr;
      }
      cdt=cdtAxisValue.forward(iUnit,iStep * (i + 1));
    }
  }
  return true;
}

Fixed version (ground truth):
/** 
 * Checks all labels for any overlap for a given axis' scale
 * @param la
 * @param iLabelLocation
 * @return
 */
public final boolean checkFit(IDisplayServer xs,Label la,int iLabelLocation) throws ChartException {
  if (isCategoryScale()) {
    return true;
  }
  final double dAngleInDegrees=la.getCaption().getFont().getRotation();
  double x=0, y=0;
  int iPointToCheck=0;
  if (iLabelLocation == ABOVE || iLabelLocation == BELOW) {
    if (iScaleDirection == BACKWARD) {
      iPointToCheck=(dAngleInDegrees < 0 && dAngleInDegrees > -90) ? 1 : 2;
    }
 else {
      iPointToCheck=(dAngleInDegrees < 0 && dAngleInDegrees > -90) ? 3 : 0;
    }
  }
 else   if (iLabelLocation == LEFT || iLabelLocation == RIGHT) {
    if (iScaleDirection == FORWARD) {
      iPointToCheck=(dAngleInDegrees < 0 && dAngleInDegrees > -90) ? 0 : 1;
    }
 else {
      iPointToCheck=(dAngleInDegrees < 0 && dAngleInDegrees > -90) ? 2 : 3;
    }
  }
  AxisTickCoordinates da=atcTickCoordinates;
  RotatedRectangle rrPrev=null, rrPrev2=null, rr;
  Double fontHeight=Methods.computeFontHeight(xs,la);
  if ((iType & (NUMERICAL | LINEAR)) == (NUMERICAL | LINEAR)) {
    double dAxisValue=asDouble(getMinimum()).doubleValue();
    final double dAxisStep=asDouble(getStep()).doubleValue();
    String sText;
    DecimalFormat df=null;
    if (fs == null) {
      df=computeDecimalFormat(dAxisValue,dAxisStep);
    }
    final NumberDataElement nde=NumberDataElementImpl.create(0);
    for (int i=0; i < da.size(); i++) {
      nde.setValue(dAxisValue);
      try {
        sText=ValueFormatter.format(nde,fs,rtc.getULocale(),df);
      }
 catch (      ChartException dfex) {
        logger.log(dfex);
        sText=NULL_STRING;
      }
      if (iLabelLocation == ABOVE || iLabelLocation == BELOW) {
        x=da.getCoordinate(i) * dZoomFactor;
      }
 else       if (iLabelLocation == LEFT || iLabelLocation == RIGHT) {
        y=da.getCoordinate(i) * dZoomFactor;
      }
      la.getCaption().setValue(sText);
      try {
        rr=computePolygon(xs,iLabelLocation,la,x,y,fontHeight);
      }
 catch (      IllegalArgumentException uiex) {
        throw new ChartException(ChartEnginePlugin.ID,ChartException.GENERATION,uiex);
      }
      if (i == 0 && bLabelWithinAxes) {
        Rectangle rect=rr.getBounds();
        if (iLabelLocation == ABOVE || iLabelLocation == BELOW) {
          rr.shiftXVertices(rect.getWidth() / 2);
        }
 else {
          rr.shiftYVertices(-rect.getHeight() / 2);
        }
      }
      Point p=rr.getPoint(iPointToCheck);
      if (isAxisLabelStaggered() && isTickLabelStaggered(i)) {
        if (rrPrev2 != null && (rrPrev2.contains(p) || rrPrev2.getPoint(iPointToCheck).equals(p) || ChartUtil.intersects(rr,rrPrev2))) {
          return false;
        }
        rrPrev2=rr;
      }
 else {
        if (rrPrev != null && (rrPrev.contains(p) || rrPrev.getPoint(iPointToCheck).equals(p) || ChartUtil.intersects(rr,rrPrev))) {
          return false;
        }
        rrPrev=rr;
      }
      dAxisValue+=dAxisStep;
    }
  }
 else   if ((iType & (NUMERICAL | LOGARITHMIC)) == (NUMERICAL | LOGARITHMIC)) {
    double dAxisValue=asDouble(getMinimum()).doubleValue();
    final double dAxisStep=asDouble(getStep()).doubleValue();
    String sText;
    NumberDataElement nde=NumberDataElementImpl.create(0);
    DecimalFormat df=null;
    for (int i=0; i < da.size() - 1; i++) {
      nde.setValue(dAxisValue);
      if (fs == null) {
        df=computeDecimalFormat(dAxisValue,dAxisStep);
      }
      try {
        sText=ValueFormatter.format(nde,fs,rtc.getULocale(),df);
      }
 catch (      ChartException dfex) {
        logger.log(dfex);
        sText=NULL_STRING;
      }
      if (iLabelLocation == ABOVE || iLabelLocation == BELOW) {
        x=da.getCoordinate(i) * dZoomFactor;
      }
 else       if (iLabelLocation == LEFT || iLabelLocation == RIGHT) {
        y=da.getCoordinate(i) * dZoomFactor;
      }
      la.getCaption().setValue(sText);
      try {
        rr=computePolygon(xs,iLabelLocation,la,x,y,fontHeight);
      }
 catch (      IllegalArgumentException uiex) {
        throw new ChartException(ChartEnginePlugin.ID,ChartException.GENERATION,uiex);
      }
      Point p=rr.getPoint(iPointToCheck);
      if (isAxisLabelStaggered() && isTickLabelStaggered(i)) {
        if (rrPrev2 != null && (rrPrev2.contains(p) || rrPrev2.getPoint(iPointToCheck).equals(p) || ChartUtil.intersects(rr,rrPrev2))) {
          return false;
        }
        rrPrev2=rr;
      }
 else {
        if (rrPrev != null && (rrPrev.contains(p) || rrPrev.getPoint(iPointToCheck).equals(p))) {
          return false;
        }
        rrPrev=rr;
      }
      dAxisValue*=dAxisStep;
    }
  }
 else   if (iType == DATE_TIME) {
    CDateTime cdt, cdtAxisValue=asDateTime(oMinimum);
    final int iUnit=asInteger(oUnit);
    final int iStep=asInteger(oStep);
    final IDateFormatWrapper sdf=DateFormatWrapperFactory.getPreferredDateFormat(iUnit,rtc.getULocale());
    String sText;
    cdt=cdtAxisValue;
    for (int i=0; i < da.size() - 1; i++) {
      sText=ValueFormatter.format(cdt,fs,rtc.getULocale(),sdf);
      if (iLabelLocation == ABOVE || iLabelLocation == BELOW) {
        x=da.getCoordinate(i) * dZoomFactor;
      }
 else       if (iLabelLocation == LEFT || iLabelLocation == RIGHT) {
        y=da.getCoordinate(i) * dZoomFactor;
      }
      la.getCaption().setValue(sText);
      try {
        rr=computePolygon(xs,iLabelLocation,la,x,y,fontHeight);
      }
 catch (      IllegalArgumentException uiex) {
        throw new ChartException(ChartEnginePlugin.ID,ChartException.GENERATION,uiex);
      }
      if (i == 0 && bLabelWithinAxes) {
        Rectangle rect=rr.getBounds();
        if (iLabelLocation == ABOVE || iLabelLocation == BELOW) {
          rr.shiftXVertices(rect.getWidth() / 2);
        }
 else {
          rr.shiftYVertices(-rect.getHeight() / 2);
        }
      }
      Point p=rr.getPoint(iPointToCheck);
      if (isAxisLabelStaggered() && isTickLabelStaggered(i)) {
        if (rrPrev2 != null && (rrPrev2.contains(p) || rrPrev2.getPoint(iPointToCheck).equals(p) || ChartUtil.intersects(rr,rrPrev2))) {
          return false;
        }
        rrPrev2=rr;
      }
 else {
        if (rrPrev != null && (rrPrev.contains(p) || rrPrev.getPoint(iPointToCheck).equals(p))) {
          return false;
        }
        rrPrev=rr;
      }
      cdt=cdtAxisValue.forward(iUnit,iStep * (i + 1));
    }
  }
  return true;
}