Program: 60103
Project: 60103
Buggy source:
/** 
 * Apply style.
 * @param availWidth the avail width
 * @param availHeight the avail height
 */
protected void applyStyle(int availWidth,int availHeight){
  Object rootNode=this.modelNode;
  HTMLElementImpl rootElement;
  boolean isRootBlock;
  if (rootNode instanceof HTMLDocumentImpl) {
    isRootBlock=true;
    HTMLDocumentImpl doc=(HTMLDocumentImpl)rootNode;
    rootElement=(HTMLElementImpl)doc.getBody();
  }
 else {
    isRootBlock=false;
    rootElement=(HTMLElementImpl)rootNode;
  }
  if (rootElement == null) {
    this.clearStyle(isRootBlock);
    return;
  }
  RenderState rs=rootElement.getRenderState();
  if (rs == null) {
    throw new IllegalStateException("String_Node_Str" + rootElement + "String_Node_Str"+ rootElement.getParentNode());
  }
  BackgroundInfo binfo=rs.getBackgroundInfo();
  this.backgroundColor=binfo == null ? null : binfo.getBackgroundColor();
  URL backgroundImage=binfo == null ? null : binfo.getBackgroundImage();
  if (backgroundImage == null) {
    this.backgroundImage=null;
    this.lastBackgroundImageUri=null;
  }
 else {
    if (!backgroundImage.equals(this.lastBackgroundImageUri)) {
      this.lastBackgroundImageUri=backgroundImage;
      this.loadBackgroundImage(backgroundImage);
    }
  }
  AbstractCSS2Properties props=rootElement.getCurrentStyle();
  if (props == null) {
    this.clearStyle(isRootBlock);
  }
 else {
    BorderInfo borderInfo=rs.getBorderInfo();
    this.borderInfo=borderInfo;
    HtmlInsets binsets=borderInfo == null ? null : borderInfo.getInsets();
    HtmlInsets minsets=rs.getMarginInsets();
    HtmlInsets pinsets=rs.getPaddingInsets();
    Insets defaultMarginInsets=this.defaultMarginInsets;
    int dmleft=0, dmright=0, dmtop=0, dmbottom=0;
    if (defaultMarginInsets != null) {
      dmleft=defaultMarginInsets.left;
      dmright=defaultMarginInsets.right;
      dmtop=defaultMarginInsets.top;
      dmbottom=defaultMarginInsets.bottom;
    }
    Insets defaultPaddingInsets=this.defaultPaddingInsets;
    int dpleft=0, dpright=0, dptop=0, dpbottom=0;
    if (defaultPaddingInsets != null) {
      dpleft=defaultPaddingInsets.left;
      dpright=defaultPaddingInsets.right;
      dptop=defaultPaddingInsets.top;
      dpbottom=defaultPaddingInsets.bottom;
    }
    Insets borderInsets=binsets == null ? null : binsets.getAWTInsets(0,0,0,0,availWidth,availHeight,0,0);
    if (borderInsets == null) {
      borderInsets=RBlockViewport.ZERO_INSETS;
    }
    Insets paddingInsets=pinsets == null ? defaultPaddingInsets : pinsets.getAWTInsets(dptop,dpleft,dpbottom,dpright,availWidth,availHeight,0,0);
    if (paddingInsets == null) {
      paddingInsets=RBlockViewport.ZERO_INSETS;
    }
    Insets tentativeMarginInsets=minsets == null ? defaultMarginInsets : minsets.getAWTInsets(dmtop,dmleft,dmbottom,dmright,availWidth,availHeight,0,0);
    if (tentativeMarginInsets == null) {
      tentativeMarginInsets=RBlockViewport.ZERO_INSETS;
    }
    int actualAvailWidth=availWidth - paddingInsets.left - paddingInsets.right- borderInsets.left- borderInsets.right- tentativeMarginInsets.left- tentativeMarginInsets.right;
    int actualAvailHeight=availHeight - paddingInsets.top - paddingInsets.bottom- borderInsets.top- borderInsets.bottom- tentativeMarginInsets.top- tentativeMarginInsets.bottom;
    Integer declaredWidth=this.getDeclaredWidth(rs,actualAvailWidth);
    Integer declaredHeight=this.getDeclaredHeight(rs,actualAvailHeight);
    int autoMarginX=0, autoMarginY=0;
    autoMarginX=(availWidth - declaredWidth.intValue() - (borderInsets == null ? 0 : borderInsets.left - borderInsets.right)- (paddingInsets == null ? 0 : paddingInsets.left - paddingInsets.right)) / 2;
    autoMarginY=(availHeight - declaredHeight.intValue() - (borderInsets == null ? 0 : borderInsets.top - borderInsets.bottom)- (paddingInsets == null ? 0 : paddingInsets.top - paddingInsets.bottom)) / 2;
    this.borderInsets=borderInsets;
    if (isRootBlock) {
      Insets regularMarginInsets=((autoMarginX == 0) && (autoMarginY == 0)) ? tentativeMarginInsets : (minsets == null ? defaultMarginInsets : minsets.getAWTInsets(dmtop,dmleft,dmbottom,dmright,availWidth,availHeight,autoMarginX,autoMarginY));
      if (regularMarginInsets == null) {
        regularMarginInsets=RBlockViewport.ZERO_INSETS;
      }
      this.marginInsets=null;
      this.paddingInsets=new Insets(paddingInsets.top + regularMarginInsets.top,paddingInsets.left + regularMarginInsets.left,paddingInsets.bottom + regularMarginInsets.bottom,paddingInsets.right + regularMarginInsets.right);
    }
 else {
      this.paddingInsets=paddingInsets;
      this.marginInsets=((autoMarginX == 0) && (autoMarginY == 0)) ? tentativeMarginInsets : (minsets == null ? defaultMarginInsets : minsets.getAWTInsets(dmtop,dmleft,dmbottom,dmright,availWidth,availHeight,autoMarginX,autoMarginY));
    }
    if (borderInfo != null) {
      this.borderTopColor=borderInfo.getTopColor();
      this.borderLeftColor=borderInfo.getLeftColor();
      this.borderBottomColor=borderInfo.getBottomColor();
      this.borderRightColor=borderInfo.getRightColor();
    }
 else {
      this.borderTopColor=null;
      this.borderLeftColor=null;
      this.borderBottomColor=null;
      this.borderRightColor=null;
    }
    String zIndex=props.getZIndex();
    if (zIndex != null) {
      try {
        this.zIndex=Integer.parseInt(zIndex);
      }
 catch (      NumberFormatException err) {
        logger.error("String_Node_Str" + zIndex + "String_Node_Str"+ this.modelNode+ "String_Node_Str",err);
        this.zIndex=0;
      }
    }
 else {
      this.zIndex=0;
    }
    this.overflowX=rs.getOverflowX();
    this.overflowY=rs.getOverflowY();
  }
}

Fixed version (ground truth):
/** 
 * Apply style.
 * @param availWidth the avail width
 * @param availHeight the avail height
 */
protected void applyStyle(int availWidth,int availHeight){
  Object rootNode=this.modelNode;
  HTMLElementImpl rootElement;
  boolean isRootBlock;
  if (rootNode instanceof HTMLDocumentImpl) {
    isRootBlock=true;
    HTMLDocumentImpl doc=(HTMLDocumentImpl)rootNode;
    rootElement=(HTMLElementImpl)doc.getBody();
  }
 else {
    isRootBlock=false;
    rootElement=(HTMLElementImpl)rootNode;
  }
  if (rootElement == null) {
    this.clearStyle(isRootBlock);
    return;
  }
  RenderState rs=rootElement.getRenderState();
  if (rs == null) {
    throw new IllegalStateException("String_Node_Str" + rootElement + "String_Node_Str"+ rootElement.getParentNode());
  }
  BackgroundInfo binfo=rs.getBackgroundInfo();
  this.backgroundColor=binfo == null ? null : binfo.getBackgroundColor();
  URL backgroundImage=binfo == null ? null : binfo.getBackgroundImage();
  if (backgroundImage == null) {
    this.backgroundImage=null;
    this.lastBackgroundImageUri=null;
  }
 else {
    if (!backgroundImage.equals(this.lastBackgroundImageUri)) {
      this.lastBackgroundImageUri=backgroundImage;
      this.loadBackgroundImage(backgroundImage);
    }
  }
  AbstractCSS2Properties props=rootElement.getCurrentStyle();
  if (props == null) {
    this.clearStyle(isRootBlock);
  }
 else {
    BorderInfo borderInfo=rs.getBorderInfo();
    this.borderInfo=borderInfo;
    HtmlInsets binsets=borderInfo == null ? null : borderInfo.getInsets();
    HtmlInsets minsets=rs.getMarginInsets();
    HtmlInsets pinsets=rs.getPaddingInsets();
    Insets defaultMarginInsets=this.defaultMarginInsets;
    int dmleft=0, dmright=0, dmtop=0, dmbottom=0;
    if (defaultMarginInsets != null) {
      dmleft=defaultMarginInsets.left;
      dmright=defaultMarginInsets.right;
      dmtop=defaultMarginInsets.top;
      dmbottom=defaultMarginInsets.bottom;
    }
    Insets defaultPaddingInsets=this.defaultPaddingInsets;
    int dpleft=0, dpright=0, dptop=0, dpbottom=0;
    if (defaultPaddingInsets != null) {
      dpleft=defaultPaddingInsets.left;
      dpright=defaultPaddingInsets.right;
      dptop=defaultPaddingInsets.top;
      dpbottom=defaultPaddingInsets.bottom;
    }
    Insets borderInsets=binsets == null ? null : binsets.getAWTInsets(0,0,0,0,availWidth,availHeight,0,0);
    if (borderInsets == null) {
      borderInsets=RBlockViewport.ZERO_INSETS;
    }
    Insets paddingInsets=pinsets == null ? defaultPaddingInsets : pinsets.getAWTInsets(dptop,dpleft,dpbottom,dpright,availWidth,availHeight,0,0);
    if (paddingInsets == null) {
      paddingInsets=RBlockViewport.ZERO_INSETS;
    }
    Insets tentativeMarginInsets=minsets == null ? defaultMarginInsets : minsets.getAWTInsets(dmtop,dmleft,dmbottom,dmright,availWidth,availHeight,0,0);
    if (tentativeMarginInsets == null) {
      tentativeMarginInsets=RBlockViewport.ZERO_INSETS;
    }
    int actualAvailWidth=availWidth - paddingInsets.left - paddingInsets.right- borderInsets.left- borderInsets.right- tentativeMarginInsets.left- tentativeMarginInsets.right;
    int actualAvailHeight=availHeight - paddingInsets.top - paddingInsets.bottom- borderInsets.top- borderInsets.bottom- tentativeMarginInsets.top- tentativeMarginInsets.bottom;
    Integer declaredWidth=this.getDeclaredWidth(rs,actualAvailWidth);
    Integer declaredHeight=this.getDeclaredHeight(rs,actualAvailHeight);
    int autoMarginX=0, autoMarginY=0;
    if (declaredWidth != null) {
      autoMarginX=(availWidth - declaredWidth.intValue() - (borderInsets == null ? 0 : borderInsets.left - borderInsets.right)- (paddingInsets == null ? 0 : paddingInsets.left - paddingInsets.right)) / 2;
    }
    if (declaredHeight != null) {
      autoMarginY=(availHeight - declaredHeight.intValue() - (borderInsets == null ? 0 : borderInsets.top - borderInsets.bottom)- (paddingInsets == null ? 0 : paddingInsets.top - paddingInsets.bottom)) / 2;
    }
    this.borderInsets=borderInsets;
    if (isRootBlock) {
      Insets regularMarginInsets=((autoMarginX == 0) && (autoMarginY == 0)) ? tentativeMarginInsets : (minsets == null ? defaultMarginInsets : minsets.getAWTInsets(dmtop,dmleft,dmbottom,dmright,availWidth,availHeight,autoMarginX,autoMarginY));
      if (regularMarginInsets == null) {
        regularMarginInsets=RBlockViewport.ZERO_INSETS;
      }
      this.marginInsets=null;
      this.paddingInsets=new Insets(paddingInsets.top + regularMarginInsets.top,paddingInsets.left + regularMarginInsets.left,paddingInsets.bottom + regularMarginInsets.bottom,paddingInsets.right + regularMarginInsets.right);
    }
 else {
      this.paddingInsets=paddingInsets;
      this.marginInsets=((autoMarginX == 0) && (autoMarginY == 0)) ? tentativeMarginInsets : (minsets == null ? defaultMarginInsets : minsets.getAWTInsets(dmtop,dmleft,dmbottom,dmright,availWidth,availHeight,autoMarginX,autoMarginY));
    }
    if (borderInfo != null) {
      this.borderTopColor=borderInfo.getTopColor();
      this.borderLeftColor=borderInfo.getLeftColor();
      this.borderBottomColor=borderInfo.getBottomColor();
      this.borderRightColor=borderInfo.getRightColor();
    }
 else {
      this.borderTopColor=null;
      this.borderLeftColor=null;
      this.borderBottomColor=null;
      this.borderRightColor=null;
    }
    String zIndex=props.getZIndex();
    if (zIndex != null) {
      try {
        this.zIndex=Integer.parseInt(zIndex);
      }
 catch (      NumberFormatException err) {
        logger.error("String_Node_Str" + zIndex + "String_Node_Str"+ this.modelNode+ "String_Node_Str",err);
        this.zIndex=0;
      }
    }
 else {
      this.zIndex=0;
    }
    this.overflowX=rs.getOverflowX();
    this.overflowY=rs.getOverflowY();
  }
}