Program: 60213
Project: 60213
Buggy source:
/** 
 * Pre paint.
 * @param g the g
 */
protected void prePaint(java.awt.Graphics g){
  int startWidth=getWidthElement();
  int startHeight=getHeightElement();
  int totalWidth=startWidth;
  int totalHeight=startHeight;
  int startX=getStartX();
  int startY=getStartY();
  ModelNode node=this.modelNode;
  RenderState rs=node.getRenderState();
  Insets marginInsets=this.marginInsets;
  if (marginInsets != null) {
    totalWidth-=(marginInsets.left + marginInsets.right);
    totalHeight-=(marginInsets.top + marginInsets.bottom);
    startX+=marginInsets.left;
    startY+=marginInsets.top;
  }
  Insets borderInsets=this.borderInsets;
  if (borderInsets != null) {
    int btop=borderInsets.top;
    int bleft=borderInsets.left;
    int bright=borderInsets.right;
    int bbottom=borderInsets.bottom;
    int newTotalWidth=totalWidth - (bleft + bright);
    int newTotalHeight=totalHeight - (btop + bbottom);
    int newStartX=startX + bleft;
    int newStartY=startY + btop;
    Rectangle clientRegion=new Rectangle(newStartX,newStartY,newTotalWidth,newTotalHeight);
    Rectangle clipBounds=g.getClipBounds();
    if (!clientRegion.contains(clipBounds)) {
      BorderInfo borderInfo=this.borderInfo;
      if (btop > 0) {
        g.setColor(this.getBorderTopColor());
        int borderStyle=borderInfo == null ? HtmlValues.BORDER_STYLE_SOLID : borderInfo.topStyle;
        for (int i=0; i < btop; i++) {
          int leftOffset=(i * bleft) / btop;
          int rightOffset=(i * bright) / btop;
          if (borderStyle == HtmlValues.BORDER_STYLE_DASHED) {
            GUITasks.drawDashed(g,startX + leftOffset,startY + i,startX + totalWidth - rightOffset - 1,startY + i,10 + btop,6);
          }
 else {
            g.drawLine(startX + leftOffset,startY + i,startX + totalWidth - rightOffset - 1,startY + i);
          }
        }
      }
      if (bright > 0) {
        int borderStyle=borderInfo == null ? HtmlValues.BORDER_STYLE_SOLID : borderInfo.rightStyle;
        g.setColor(this.getBorderRightColor());
        int lastX=startX + totalWidth - 1;
        for (int i=0; i < bright; i++) {
          int topOffset=(i * btop) / bright;
          int bottomOffset=(i * bbottom) / bright;
          if (borderStyle == HtmlValues.BORDER_STYLE_DASHED) {
            GUITasks.drawDashed(g,lastX - i,startY + topOffset,lastX - i,startY + totalHeight - bottomOffset - 1,10 + bright,6);
          }
 else {
            g.drawLine(lastX - i,startY + topOffset,lastX - i,startY + totalHeight - bottomOffset - 1);
          }
        }
      }
      if (bbottom > 0) {
        int borderStyle=borderInfo == null ? HtmlValues.BORDER_STYLE_SOLID : borderInfo.bottomStyle;
        g.setColor(this.getBorderBottomColor());
        int lastY=startY + totalHeight - 1;
        for (int i=0; i < bbottom; i++) {
          int leftOffset=(i * bleft) / bbottom;
          int rightOffset=(i * bright) / bbottom;
          if (borderStyle == HtmlValues.BORDER_STYLE_DASHED) {
            GUITasks.drawDashed(g,startX + leftOffset,lastY - i,startX + totalWidth - rightOffset - 1,lastY - i,10 + bbottom,6);
          }
 else {
            g.drawLine(startX + leftOffset,lastY - i,startX + totalWidth - rightOffset - 1,lastY - i);
          }
        }
      }
      if (bleft > 0) {
        int borderStyle=borderInfo == null ? HtmlValues.BORDER_STYLE_SOLID : borderInfo.leftStyle;
        g.setColor(this.getBorderLeftColor());
        for (int i=0; i < bleft; i++) {
          int topOffset=(i * btop) / bleft;
          int bottomOffset=(i * bbottom) / bleft;
          if (borderStyle == HtmlValues.BORDER_STYLE_DASHED) {
            GUITasks.drawDashed(g,startX + i,startY + topOffset,startX + i,startY + totalHeight - bottomOffset - 1,10 + bleft,6);
          }
 else {
            g.drawLine(startX + i,startY + topOffset,startX + i,startY + totalHeight - bottomOffset - 1);
          }
        }
      }
    }
    totalWidth=newTotalWidth;
    totalHeight=newTotalHeight;
    startX=newStartX;
    startY=newStartY;
  }
  Graphics clientG=g.create(startX,startY,totalWidth,totalHeight);
  try {
    Rectangle bkgBounds=null;
    if (node != null) {
      Color bkg=this.backgroundColor;
      if (bkg != null && bkg.getAlpha() > 0) {
        clientG.setColor(bkg);
        bkgBounds=clientG.getClipBounds();
        clientG.fillRect(bkgBounds.x,bkgBounds.y,bkgBounds.width,bkgBounds.height);
      }
      BackgroundInfo binfo=rs == null ? null : rs.getBackgroundInfo();
      Image image=this.backgroundImage;
      if (image != null) {
        if (bkgBounds == null) {
          bkgBounds=clientG.getClipBounds();
        }
        int w=image.getWidth(this);
        int h=image.getHeight(this);
        if (w != -1 && h != -1) {
switch (binfo == null ? BackgroundInfo.BR_REPEAT : binfo.backgroundRepeat) {
case BackgroundInfo.BR_NO_REPEAT:
{
              int imageX;
              if (binfo.backgroundXPositionAbsolute) {
                imageX=binfo.backgroundXPosition;
              }
 else {
                imageX=(binfo.backgroundXPosition * (totalWidth - w)) / 100;
              }
              int imageY;
              if (binfo.backgroundYPositionAbsolute) {
                imageY=binfo.backgroundYPosition;
              }
 else {
                imageY=(binfo.backgroundYPosition * (totalHeight - h)) / 100;
              }
              clientG.drawImage(image,imageX,imageY,w,h,this);
              break;
            }
case BackgroundInfo.BR_REPEAT_X:
{
            int imageY;
            if (binfo.backgroundYPositionAbsolute) {
              imageY=binfo.backgroundYPosition;
            }
 else {
              imageY=(binfo.backgroundYPosition * (totalHeight - h)) / 100;
            }
            int x=(bkgBounds.x / w) * w;
            int topX=bkgBounds.x + bkgBounds.width;
            for (; x < topX; x+=w) {
              clientG.drawImage(image,x,imageY,w,h,this);
            }
            break;
          }
case BackgroundInfo.BR_REPEAT_Y:
{
          int imageX;
          if (binfo.backgroundXPositionAbsolute) {
            imageX=binfo.backgroundXPosition;
          }
 else {
            imageX=(binfo.backgroundXPosition * (totalWidth - w)) / 100;
          }
          int y=(bkgBounds.y / h) * h;
          int topY=bkgBounds.y + bkgBounds.height;
          for (; y < topY; y+=h) {
            clientG.drawImage(image,imageX,y,w,h,this);
          }
          break;
        }
default :
{
        int baseX=(bkgBounds.x / w) * w;
        int baseY=(bkgBounds.y / h) * h;
        int topX=bkgBounds.x + bkgBounds.width;
        int topY=bkgBounds.y + bkgBounds.height;
        for (int x=baseX; x < topX; x+=w) {
          for (int y=baseY; y < topY; y+=h) {
            clientG.drawImage(image,x,y,w,h,this);
          }
        }
        break;
      }
  }
}
}
}
}
  finally {
clientG.dispose();
}
}

Fixed version (ground truth):
/** 
 * Pre paint.
 * @param g the g
 */
protected void prePaint(java.awt.Graphics g){
  int startWidth=getWidthElement();
  int startHeight=getHeightElement();
  int totalWidth=startWidth;
  int totalHeight=startHeight;
  int startX=getStartX();
  int startY=getStartY();
  ModelNode node=this.modelNode;
  RenderState rs=node.getRenderState();
  Insets marginInsets=this.marginInsets;
  if (marginInsets != null) {
    totalWidth-=(marginInsets.left + marginInsets.right);
    totalHeight-=(marginInsets.top + marginInsets.bottom);
    startX+=marginInsets.left;
    startY+=marginInsets.top;
  }
  Insets borderInsets=this.borderInsets;
  if (borderInsets != null) {
    int btop=borderInsets.top;
    int bleft=borderInsets.left;
    int bright=borderInsets.right;
    int bbottom=borderInsets.bottom;
    int newTotalWidth=totalWidth - (bleft + bright);
    int newTotalHeight=totalHeight - (btop + bbottom);
    int newStartX=startX + bleft;
    int newStartY=startY + btop;
    Rectangle clientRegion=new Rectangle(newStartX,newStartY,newTotalWidth,newTotalHeight);
    Rectangle clipBounds=g.getClipBounds();
    if (!clientRegion.contains(clipBounds)) {
      BorderInfo borderInfo=this.borderInfo;
      if (btop > 0) {
        g.setColor(this.getBorderTopColor());
        int borderStyle=borderInfo == null ? HtmlValues.BORDER_STYLE_SOLID : borderInfo.getTopStyle();
        for (int i=0; i < btop; i++) {
          int leftOffset=(i * bleft) / btop;
          int rightOffset=(i * bright) / btop;
          if (borderStyle == HtmlValues.BORDER_STYLE_DASHED) {
            GUITasks.drawDashed(g,startX + leftOffset,startY + i,startX + totalWidth - rightOffset - 1,startY + i,10 + btop,6);
          }
 else {
            g.drawLine(startX + leftOffset,startY + i,startX + totalWidth - rightOffset - 1,startY + i);
          }
        }
      }
      if (bright > 0) {
        int borderStyle=borderInfo == null ? HtmlValues.BORDER_STYLE_SOLID : borderInfo.getRightStyle();
        g.setColor(this.getBorderRightColor());
        int lastX=startX + totalWidth - 1;
        for (int i=0; i < bright; i++) {
          int topOffset=(i * btop) / bright;
          int bottomOffset=(i * bbottom) / bright;
          if (borderStyle == HtmlValues.BORDER_STYLE_DASHED) {
            GUITasks.drawDashed(g,lastX - i,startY + topOffset,lastX - i,startY + totalHeight - bottomOffset - 1,10 + bright,6);
          }
 else {
            g.drawLine(lastX - i,startY + topOffset,lastX - i,startY + totalHeight - bottomOffset - 1);
          }
        }
      }
      if (bbottom > 0) {
        int borderStyle=borderInfo == null ? HtmlValues.BORDER_STYLE_SOLID : borderInfo.getBottomStyle();
        g.setColor(this.getBorderBottomColor());
        int lastY=startY + totalHeight - 1;
        for (int i=0; i < bbottom; i++) {
          int leftOffset=(i * bleft) / bbottom;
          int rightOffset=(i * bright) / bbottom;
          if (borderStyle == HtmlValues.BORDER_STYLE_DASHED) {
            GUITasks.drawDashed(g,startX + leftOffset,lastY - i,startX + totalWidth - rightOffset - 1,lastY - i,10 + bbottom,6);
          }
 else {
            g.drawLine(startX + leftOffset,lastY - i,startX + totalWidth - rightOffset - 1,lastY - i);
          }
        }
      }
      if (bleft > 0) {
        int borderStyle=borderInfo == null ? HtmlValues.BORDER_STYLE_SOLID : borderInfo.getLeftStyle();
        g.setColor(this.getBorderLeftColor());
        for (int i=0; i < bleft; i++) {
          int topOffset=(i * btop) / bleft;
          int bottomOffset=(i * bbottom) / bleft;
          if (borderStyle == HtmlValues.BORDER_STYLE_DASHED) {
            GUITasks.drawDashed(g,startX + i,startY + topOffset,startX + i,startY + totalHeight - bottomOffset - 1,10 + bleft,6);
          }
 else {
            g.drawLine(startX + i,startY + topOffset,startX + i,startY + totalHeight - bottomOffset - 1);
          }
        }
      }
    }
    totalWidth=newTotalWidth;
    totalHeight=newTotalHeight;
    startX=newStartX;
    startY=newStartY;
  }
  Graphics clientG=g.create(startX,startY,totalWidth,totalHeight);
  try {
    Rectangle bkgBounds=null;
    if (node != null) {
      Color bkg=this.backgroundColor;
      if (bkg != null && bkg.getAlpha() > 0) {
        clientG.setColor(bkg);
        bkgBounds=clientG.getClipBounds();
        clientG.fillRect(bkgBounds.x,bkgBounds.y,bkgBounds.width,bkgBounds.height);
      }
      BackgroundInfo binfo=rs == null ? null : rs.getBackgroundInfo();
      Image image=this.backgroundImage;
      if (image != null) {
        if (bkgBounds == null) {
          bkgBounds=clientG.getClipBounds();
        }
        int w=image.getWidth(this);
        int h=image.getHeight(this);
        if (w != -1 && h != -1) {
switch (binfo == null ? BackgroundInfo.BR_REPEAT : binfo.backgroundRepeat) {
case BackgroundInfo.BR_NO_REPEAT:
{
              int imageX;
              if (binfo.backgroundXPositionAbsolute) {
                imageX=binfo.backgroundXPosition;
              }
 else {
                imageX=(binfo.backgroundXPosition * (totalWidth - w)) / 100;
              }
              int imageY;
              if (binfo.backgroundYPositionAbsolute) {
                imageY=binfo.backgroundYPosition;
              }
 else {
                imageY=(binfo.backgroundYPosition * (totalHeight - h)) / 100;
              }
              clientG.drawImage(image,imageX,imageY,w,h,this);
              break;
            }
case BackgroundInfo.BR_REPEAT_X:
{
            int imageY;
            if (binfo.backgroundYPositionAbsolute) {
              imageY=binfo.backgroundYPosition;
            }
 else {
              imageY=(binfo.backgroundYPosition * (totalHeight - h)) / 100;
            }
            int x=(bkgBounds.x / w) * w;
            int topX=bkgBounds.x + bkgBounds.width;
            for (; x < topX; x+=w) {
              clientG.drawImage(image,x,imageY,w,h,this);
            }
            break;
          }
case BackgroundInfo.BR_REPEAT_Y:
{
          int imageX;
          if (binfo.backgroundXPositionAbsolute) {
            imageX=binfo.backgroundXPosition;
          }
 else {
            imageX=(binfo.backgroundXPosition * (totalWidth - w)) / 100;
          }
          int y=(bkgBounds.y / h) * h;
          int topY=bkgBounds.y + bkgBounds.height;
          for (; y < topY; y+=h) {
            clientG.drawImage(image,imageX,y,w,h,this);
          }
          break;
        }
default :
{
        int baseX=(bkgBounds.x / w) * w;
        int baseY=(bkgBounds.y / h) * h;
        int topX=bkgBounds.x + bkgBounds.width;
        int topY=bkgBounds.y + bkgBounds.height;
        for (int x=baseX; x < topX; x+=w) {
          for (int y=baseY; y < topY; y+=h) {
            clientG.drawImage(image,x,y,w,h,this);
          }
        }
        break;
      }
  }
}
}
}
}
  finally {
clientG.dispose();
}
}