Program: 71399
Project: 71399
Buggy source:
/** 
 * @param xs
 * @param iLabelLocation
 * @param la
 * @param dX
 * @param dY
 * @param dWrapping the max size for wrapping by pixels
 * @return
 * @throws IllegalArgumentException
 */
public static final BoundingBox computeBox(IDisplayServer xs,int iLabelLocation,Label la,double dX,double dY,double dWrapping) throws IllegalArgumentException {
  double dAngleInDegrees=la.getCaption().getFont().getRotation();
  if (dAngleInDegrees < -90 || dAngleInDegrees > 90) {
    throw new IllegalArgumentException(MessageFormat.format(Messages.getResourceBundle(xs.getULocale()).getString("String_Node_Str"),new Object[]{la}));
  }
  final double dAngleInRadians=((-dAngleInDegrees * Math.PI) / 180.0);
  final double dSineTheta=Math.abs(Math.sin(dAngleInRadians));
  final double dCosTheta=Math.abs(Math.cos(dAngleInRadians));
  final ITextMetrics itm=xs.getTextMetrics(la);
  try {
    if (dWrapping > 0) {
      itm.reuse(la,dWrapping);
    }
    double dW=itm.getFullWidth();
    double dH=itm.getFullHeight();
    BoundingBox bb=null;
    if ((iLabelLocation & LEFT) == LEFT) {
      if (dAngleInDegrees == 0) {
        bb=new BoundingBox(LEFT,dX - dW,dY - dH / 2,dW,dH,dH / 2);
      }
 else       if (dAngleInDegrees > 0 && dAngleInDegrees < 90) {
        bb=new BoundingBox(LEFT,dX - (dH * dSineTheta + dW * dCosTheta),dY - dH * dCosTheta,dH * dSineTheta + dW * dCosTheta,dH * dCosTheta + dW * dSineTheta,dH * dCosTheta);
      }
 else       if (dAngleInDegrees < 0 && dAngleInDegrees > -90) {
        bb=new BoundingBox(LEFT,dX - (dH * dSineTheta + dW * dCosTheta),dY - dW * dSineTheta,dH * dSineTheta + dW * dCosTheta,dH * dCosTheta + dW * dSineTheta,dW * dSineTheta);
      }
 else       if (dAngleInDegrees == 90 || dAngleInDegrees == -90) {
        bb=new BoundingBox(LEFT,dX - dH,dY - dW / 2,dH,dW,dW / 2);
      }
    }
 else     if ((iLabelLocation & RIGHT) == RIGHT) {
      if (dAngleInDegrees == 0) {
        bb=new BoundingBox(RIGHT,dX,dY - dH / 2,dW,dH,dH / 2);
      }
 else       if (dAngleInDegrees > 0 && dAngleInDegrees < 90) {
        bb=new BoundingBox(RIGHT,dX,dY - dW * dSineTheta,dH * dSineTheta + dW * dCosTheta,dH * dCosTheta + dW * dSineTheta,dW * dSineTheta);
      }
 else       if (dAngleInDegrees < 0 && dAngleInDegrees > -90) {
        bb=new BoundingBox(RIGHT,dX,dY - dH * dCosTheta,dH * dSineTheta + dW * dCosTheta,dH * dCosTheta + dW * dSineTheta,dH * dCosTheta);
      }
 else       if (dAngleInDegrees == 90 || dAngleInDegrees == -90) {
        bb=new BoundingBox(RIGHT,dX,dY - dW / 2,dH,dW,dW / 2);
      }
    }
 else     if ((iLabelLocation & BOTTOM) == BOTTOM) {
      if (dAngleInDegrees == 0) {
        bb=new BoundingBox(BOTTOM,dX - dW / 2,dY,dW,dH,dW / 2);
      }
 else       if (dAngleInDegrees > 0 && dAngleInDegrees < 90) {
        bb=new BoundingBox(BOTTOM,dX - dW * dCosTheta,dY,dH * dSineTheta + dW * dCosTheta,dH * dCosTheta + dW * dSineTheta,dW * dCosTheta);
      }
 else       if (dAngleInDegrees < 0 && dAngleInDegrees > -90) {
        bb=new BoundingBox(BOTTOM,dX - dH * dSineTheta,dY,dH * dSineTheta + dW * dCosTheta,dH * dCosTheta + dW * dSineTheta,dH * dSineTheta);
      }
 else       if (dAngleInDegrees == 90 || dAngleInDegrees == -90) {
        bb=new BoundingBox(BOTTOM,dX - dH / 2,dY,dH,dW,dH / 2);
      }
    }
 else     if ((iLabelLocation & TOP) == TOP) {
      if (dAngleInDegrees == 0) {
        bb=new BoundingBox(TOP,dX - dW / 2,dY - dH,dW,dH,dW / 2);
      }
 else       if (dAngleInDegrees > 0 && dAngleInDegrees < 90) {
        bb=new BoundingBox(TOP,dX - dH * dSineTheta,dY - (dH * dCosTheta + dW * dSineTheta),dH * dSineTheta + dW * dCosTheta,dH * dCosTheta + dW * dSineTheta,dH * dSineTheta);
      }
 else       if (dAngleInDegrees < 0 && dAngleInDegrees > -90) {
        bb=new BoundingBox(TOP,dX - dW * dCosTheta,dY - (dH * dCosTheta + dW * dSineTheta),dH * dSineTheta + dW * dCosTheta,dH * dCosTheta + dW * dSineTheta,dW * dCosTheta);
      }
 else       if (dAngleInDegrees == 90 || dAngleInDegrees == -90) {
        bb=new BoundingBox(TOP,dX - dH / 2,dY - dW,dH,dW,dH / 2);
      }
    }
 else     if ((iLabelLocation & INSIDE) == INSIDE) {
      if (dAngleInDegrees == 0) {
        bb=new BoundingBox(INSIDE,dX - dW / 2,dY - dH / 2,dW,dH,0);
      }
 else       if (dAngleInDegrees > 0 && dAngleInDegrees < 90) {
        bb=new BoundingBox(INSIDE,dX - (dH * dSineTheta + dW * dCosTheta) / 2,dY - (dH * dCosTheta + dW * dSineTheta) / 2,dH * dSineTheta + dW * dCosTheta,dH * dCosTheta + dW * dSineTheta,0);
      }
 else       if (dAngleInDegrees < 0 && dAngleInDegrees > -90) {
        bb=new BoundingBox(INSIDE,dX - (dW * dCosTheta + dH * dSineTheta) / 2,dY - (dH * dCosTheta + dW * dSineTheta) / 2,dH * dSineTheta + dW * dCosTheta,dH * dCosTheta + dW * dSineTheta,0);
      }
 else       if (dAngleInDegrees == 90 || dAngleInDegrees == -90) {
        bb=new BoundingBox(INSIDE,dX - dH / 2,dY - dW / 2,dH,dW,0);
      }
    }
    return bb;
  }
  finally {
    itm.dispose();
  }
}

Fixed version (ground truth):
public static final BoundingBox computeBox(IDisplayServer xs,int iLabelLocation,Label la,double dX,double dY,double dWrapping,Double fontHeight) throws IllegalArgumentException {
  double dAngleInDegrees=la.getCaption().getFont().getRotation();
  if (dAngleInDegrees < -90 || dAngleInDegrees > 90) {
    throw new IllegalArgumentException(MessageFormat.format(Messages.getResourceBundle(xs.getULocale()).getString("String_Node_Str"),new Object[]{la}));
  }
  final double dAngleInRadians=((-dAngleInDegrees * Math.PI) / 180.0);
  final double dSineTheta=Math.abs(Math.sin(dAngleInRadians));
  final double dCosTheta=Math.abs(Math.cos(dAngleInRadians));
  final ITextMetrics itm=xs.getTextMetrics(la);
  try {
    if (dWrapping > 0) {
      itm.reuse(la,dWrapping);
    }
    double dW=itm.getFullWidth();
    double dH=fontHeight == null ? itm.getFullHeight() : itm.getFullHeight(fontHeight);
    BoundingBox bb=null;
    if ((iLabelLocation & LEFT) == LEFT) {
      if (dAngleInDegrees == 0) {
        bb=new BoundingBox(LEFT,dX - dW,dY - dH / 2,dW,dH,dH / 2);
      }
 else       if (dAngleInDegrees > 0 && dAngleInDegrees < 90) {
        bb=new BoundingBox(LEFT,dX - (dH * dSineTheta + dW * dCosTheta),dY - dH * dCosTheta,dH * dSineTheta + dW * dCosTheta,dH * dCosTheta + dW * dSineTheta,dH * dCosTheta);
      }
 else       if (dAngleInDegrees < 0 && dAngleInDegrees > -90) {
        bb=new BoundingBox(LEFT,dX - (dH * dSineTheta + dW * dCosTheta),dY - dW * dSineTheta,dH * dSineTheta + dW * dCosTheta,dH * dCosTheta + dW * dSineTheta,dW * dSineTheta);
      }
 else       if (dAngleInDegrees == 90 || dAngleInDegrees == -90) {
        bb=new BoundingBox(LEFT,dX - dH,dY - dW / 2,dH,dW,dW / 2);
      }
    }
 else     if ((iLabelLocation & RIGHT) == RIGHT) {
      if (dAngleInDegrees == 0) {
        bb=new BoundingBox(RIGHT,dX,dY - dH / 2,dW,dH,dH / 2);
      }
 else       if (dAngleInDegrees > 0 && dAngleInDegrees < 90) {
        bb=new BoundingBox(RIGHT,dX,dY - dW * dSineTheta,dH * dSineTheta + dW * dCosTheta,dH * dCosTheta + dW * dSineTheta,dW * dSineTheta);
      }
 else       if (dAngleInDegrees < 0 && dAngleInDegrees > -90) {
        bb=new BoundingBox(RIGHT,dX,dY - dH * dCosTheta,dH * dSineTheta + dW * dCosTheta,dH * dCosTheta + dW * dSineTheta,dH * dCosTheta);
      }
 else       if (dAngleInDegrees == 90 || dAngleInDegrees == -90) {
        bb=new BoundingBox(RIGHT,dX,dY - dW / 2,dH,dW,dW / 2);
      }
    }
 else     if ((iLabelLocation & BOTTOM) == BOTTOM) {
      if (dAngleInDegrees == 0) {
        bb=new BoundingBox(BOTTOM,dX - dW / 2,dY,dW,dH,dW / 2);
      }
 else       if (dAngleInDegrees > 0 && dAngleInDegrees < 90) {
        bb=new BoundingBox(BOTTOM,dX - dW * dCosTheta,dY,dH * dSineTheta + dW * dCosTheta,dH * dCosTheta + dW * dSineTheta,dW * dCosTheta);
      }
 else       if (dAngleInDegrees < 0 && dAngleInDegrees > -90) {
        bb=new BoundingBox(BOTTOM,dX - dH * dSineTheta,dY,dH * dSineTheta + dW * dCosTheta,dH * dCosTheta + dW * dSineTheta,dH * dSineTheta);
      }
 else       if (dAngleInDegrees == 90 || dAngleInDegrees == -90) {
        bb=new BoundingBox(BOTTOM,dX - dH / 2,dY,dH,dW,dH / 2);
      }
    }
 else     if ((iLabelLocation & TOP) == TOP) {
      if (dAngleInDegrees == 0) {
        bb=new BoundingBox(TOP,dX - dW / 2,dY - dH,dW,dH,dW / 2);
      }
 else       if (dAngleInDegrees > 0 && dAngleInDegrees < 90) {
        bb=new BoundingBox(TOP,dX - dH * dSineTheta,dY - (dH * dCosTheta + dW * dSineTheta),dH * dSineTheta + dW * dCosTheta,dH * dCosTheta + dW * dSineTheta,dH * dSineTheta);
      }
 else       if (dAngleInDegrees < 0 && dAngleInDegrees > -90) {
        bb=new BoundingBox(TOP,dX - dW * dCosTheta,dY - (dH * dCosTheta + dW * dSineTheta),dH * dSineTheta + dW * dCosTheta,dH * dCosTheta + dW * dSineTheta,dW * dCosTheta);
      }
 else       if (dAngleInDegrees == 90 || dAngleInDegrees == -90) {
        bb=new BoundingBox(TOP,dX - dH / 2,dY - dW,dH,dW,dH / 2);
      }
    }
 else     if ((iLabelLocation & INSIDE) == INSIDE) {
      if (dAngleInDegrees == 0) {
        bb=new BoundingBox(INSIDE,dX - dW / 2,dY - dH / 2,dW,dH,0);
      }
 else       if (dAngleInDegrees > 0 && dAngleInDegrees < 90) {
        bb=new BoundingBox(INSIDE,dX - (dH * dSineTheta + dW * dCosTheta) / 2,dY - (dH * dCosTheta + dW * dSineTheta) / 2,dH * dSineTheta + dW * dCosTheta,dH * dCosTheta + dW * dSineTheta,0);
      }
 else       if (dAngleInDegrees < 0 && dAngleInDegrees > -90) {
        bb=new BoundingBox(INSIDE,dX - (dW * dCosTheta + dH * dSineTheta) / 2,dY - (dH * dCosTheta + dW * dSineTheta) / 2,dH * dSineTheta + dW * dCosTheta,dH * dCosTheta + dW * dSineTheta,0);
      }
 else       if (dAngleInDegrees == 90 || dAngleInDegrees == -90) {
        bb=new BoundingBox(INSIDE,dX - dH / 2,dY - dW / 2,dH,dW,0);
      }
    }
    return bb;
  }
  finally {
    itm.dispose();
  }
}