Program: 76881
Project: 76881
Buggy source:
/** 
 * The iconifyFrame() code calls this to determine the proper bounds for the desktopIcon.
 */
protected Rectangle getBoundsForIconOf(JInternalFrame f){
  JInternalFrame.JDesktopIcon icon=f.getDesktopIcon();
  Dimension prefSize=icon.getPreferredSize();
  Container c=f.getParent();
  if (c == null) {
    c=f.getDesktopIcon().getParent();
  }
  if (c == null) {
    return new Rectangle(0,0,prefSize.width,prefSize.height);
  }
  Rectangle parentBounds=c.getBounds();
  Component[] components=c.getComponents();
  Rectangle availableRectangle=null;
  JInternalFrame.JDesktopIcon currentIcon=null;
  int x=0;
  int y=parentBounds.height - prefSize.height;
  int w=prefSize.width;
  int h=prefSize.height;
  boolean found=false;
  while (!found) {
    availableRectangle=new Rectangle(x,y,w,h);
    found=true;
    for (int i=0; i < components.length; i++) {
      if (components[i] instanceof JInternalFrame) {
        currentIcon=((JInternalFrame)components[i]).getDesktopIcon();
      }
 else       if (components[i] instanceof JInternalFrame.JDesktopIcon) {
        currentIcon=(JInternalFrame.JDesktopIcon)components[i];
      }
 else       continue;
      if (!currentIcon.equals(icon)) {
        if (availableRectangle.intersects(currentIcon.getBounds())) {
          found=false;
          break;
        }
      }
    }
    if (currentIcon == null)     return availableRectangle;
    x+=currentIcon.getBounds().width;
    if (x + w > parentBounds.width) {
      x=0;
      y-=h;
    }
  }
  return (availableRectangle);
}

Fixed version (ground truth):
/** 
 * The   {@code iconifyFrame()} code calls this to determine the proper boundsfor the desktopIcon.
 * @param f the {@code JInternalFrame} of interest
 * @return a {@code Rectangle} containing bounds for the {@code desktopIcon}
 */
protected Rectangle getBoundsForIconOf(JInternalFrame f){
  JInternalFrame.JDesktopIcon icon=f.getDesktopIcon();
  Dimension prefSize=icon.getPreferredSize();
  Container c=f.getParent();
  if (c == null) {
    c=f.getDesktopIcon().getParent();
  }
  if (c == null) {
    return new Rectangle(0,0,prefSize.width,prefSize.height);
  }
  Rectangle parentBounds=c.getBounds();
  Component[] components=c.getComponents();
  Rectangle availableRectangle=null;
  JInternalFrame.JDesktopIcon currentIcon=null;
  int x=0;
  int y=parentBounds.height - prefSize.height;
  int w=prefSize.width;
  int h=prefSize.height;
  boolean found=false;
  while (!found) {
    availableRectangle=new Rectangle(x,y,w,h);
    found=true;
    for (int i=0; i < components.length; i++) {
      if (components[i] instanceof JInternalFrame) {
        currentIcon=((JInternalFrame)components[i]).getDesktopIcon();
      }
 else       if (components[i] instanceof JInternalFrame.JDesktopIcon) {
        currentIcon=(JInternalFrame.JDesktopIcon)components[i];
      }
 else       continue;
      if (!currentIcon.equals(icon)) {
        if (availableRectangle.intersects(currentIcon.getBounds())) {
          found=false;
          break;
        }
      }
    }
    if (currentIcon == null)     return availableRectangle;
    x+=currentIcon.getBounds().width;
    if (x + w > parentBounds.width) {
      x=0;
      y-=h;
    }
  }
  return (availableRectangle);
}