Program: 76839
Project: 76839
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 (iType == TEXT || bCategoryScale) {
    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;
    }
  }
  double[] da=daTickCoordinates;
  RotatedRectangle rrPrev=null, rrPrev2=null, rr;
  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=new DecimalFormat(getNumericPattern());
    }
    final NumberDataElement nde=NumberDataElementImpl.create(0);
    for (int i=0; i < da.length; 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[i] * dZoomFactor;
      }
 else       if (iLabelLocation == LEFT || iLabelLocation == RIGHT) {
        y=da[i] * dZoomFactor;
      }
      la.getCaption().setValue(sText);
      try {
        rr=computePolygon(xs,iLabelLocation,la,x,y);
      }
 catch (      IllegalArgumentException uiex) {
        throw new ChartException(ChartEnginePlugin.ID,ChartException.GENERATION,uiex);
      }
      Point p=rr.getPoint(iPointToCheck);
      if (isAxisLabelStaggered() && baTickLabelStaggered[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.length; i++) {
      nde.setValue(dAxisValue);
      if (fs == null) {
        df=new DecimalFormat(getNumericPattern(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[i] * dZoomFactor;
      }
 else       if (iLabelLocation == LEFT || iLabelLocation == RIGHT) {
        y=da[i] * dZoomFactor;
      }
      la.getCaption().setValue(sText);
      try {
        rr=computePolygon(xs,iLabelLocation,la,x,y);
      }
 catch (      IllegalArgumentException uiex) {
        throw new ChartException(ChartEnginePlugin.ID,ChartException.GENERATION,uiex);
      }
      Point p=rr.getPoint(iPointToCheck);
      if (isAxisLabelStaggered() && baTickLabelStaggered[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.length; i++) {
      sText=ValueFormatter.format(cdt,fs,rtc.getULocale(),sdf);
      if (iLabelLocation == ABOVE || iLabelLocation == BELOW) {
        x=da[i] * dZoomFactor;
      }
 else       if (iLabelLocation == LEFT || iLabelLocation == RIGHT) {
        y=da[i] * dZoomFactor;
      }
      la.getCaption().setValue(sText);
      try {
        rr=computePolygon(xs,iLabelLocation,la,x,y);
      }
 catch (      IllegalArgumentException uiex) {
        throw new ChartException(ChartEnginePlugin.ID,ChartException.GENERATION,uiex);
      }
      Point p=rr.getPoint(iPointToCheck);
      if (isAxisLabelStaggered() && baTickLabelStaggered[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 (iType == TEXT || bCategoryScale) {
    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;
    }
  }
  double[] da=daTickCoordinates;
  RotatedRectangle rrPrev=null, rrPrev2=null, rr;
  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=new DecimalFormat(getNumericPattern());
    }
    final NumberDataElement nde=NumberDataElementImpl.create(0);
    for (int i=0; i < da.length - 1; 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[i] * dZoomFactor;
      }
 else       if (iLabelLocation == LEFT || iLabelLocation == RIGHT) {
        y=da[i] * dZoomFactor;
      }
      la.getCaption().setValue(sText);
      try {
        rr=computePolygon(xs,iLabelLocation,la,x,y);
      }
 catch (      IllegalArgumentException uiex) {
        throw new ChartException(ChartEnginePlugin.ID,ChartException.GENERATION,uiex);
      }
      Point p=rr.getPoint(iPointToCheck);
      if (isAxisLabelStaggered() && baTickLabelStaggered[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.length - 1; i++) {
      nde.setValue(dAxisValue);
      if (fs == null) {
        df=new DecimalFormat(getNumericPattern(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[i] * dZoomFactor;
      }
 else       if (iLabelLocation == LEFT || iLabelLocation == RIGHT) {
        y=da[i] * dZoomFactor;
      }
      la.getCaption().setValue(sText);
      try {
        rr=computePolygon(xs,iLabelLocation,la,x,y);
      }
 catch (      IllegalArgumentException uiex) {
        throw new ChartException(ChartEnginePlugin.ID,ChartException.GENERATION,uiex);
      }
      Point p=rr.getPoint(iPointToCheck);
      if (isAxisLabelStaggered() && baTickLabelStaggered[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.length - 1; i++) {
      sText=ValueFormatter.format(cdt,fs,rtc.getULocale(),sdf);
      if (iLabelLocation == ABOVE || iLabelLocation == BELOW) {
        x=da[i] * dZoomFactor;
      }
 else       if (iLabelLocation == LEFT || iLabelLocation == RIGHT) {
        y=da[i] * dZoomFactor;
      }
      la.getCaption().setValue(sText);
      try {
        rr=computePolygon(xs,iLabelLocation,la,x,y);
      }
 catch (      IllegalArgumentException uiex) {
        throw new ChartException(ChartEnginePlugin.ID,ChartException.GENERATION,uiex);
      }
      Point p=rr.getPoint(iPointToCheck);
      if (isAxisLabelStaggered() && baTickLabelStaggered[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;
}