Program: 72289
Project: 72289
Buggy source:
/** 
 * Output a layout PageArea, extend the pageArea into multiple physical pages if needed.
 * @param page
 */
protected void visitPage(PageArea page){
  scale=page.getScale();
  if (page.isExtendToMultiplePages()) {
    int pageBodyHeight=getActualPageBodyHeight(page);
    int pageBodyWidth=getActualPageBodyWidth(page);
    int definedBodyHeight=page.getBody().getHeight();
    int definedBodyWidth=page.getBody().getWidth();
    if (pageBodyHeight > definedBodyHeight) {
      addExtendDirection(EXTEND_ON_VERTICAL);
    }
    if (pageBodyWidth > definedBodyWidth) {
      addExtendDirection(EXTEND_ON_HORIZONTAL);
    }
    offsetX=0;
    offsetY=0;
    if (extendDirection == EXTEND_NONE) {
      addPage(page);
    }
 else     if (extendDirection == EXTEND_ON_HORIZONTAL) {
      do {
        addPage(page);
        offsetX+=definedBodyWidth;
      }
 while (offsetX < pageBodyWidth - ignoredOverflow);
    }
 else     if (extendDirection == EXTEND_ON_VERTICAL) {
      do {
        addPage(page);
        offsetY+=definedBodyHeight;
      }
 while (offsetY < pageBodyHeight - ignoredOverflow);
    }
 else     if (extendDirection == EXTEND_ON_HORIZONTAL_AND_VERTICAL) {
      do {
        do {
          addPage(page);
          offsetX+=definedBodyWidth;
        }
 while (offsetX < pageBodyWidth - ignoredOverflow);
        offsetX=0;
        offsetY+=definedBodyHeight;
      }
 while (offsetY < pageBodyHeight - ignoredOverflow);
    }
    setExtendDirection(EXTEND_NONE);
  }
 else {
    addPage(page);
  }
}

Fixed version (ground truth):
/** 
 * Output a layout PageArea, extend the pageArea into multiple physical pages if needed.
 * @param page
 */
protected void visitPage(PageArea page){
  scale=page.getScale();
  if (page.isExtendToMultiplePages()) {
    int pageBodyHeight=getActualPageBodyHeight(page);
    int pageBodyWidth=getActualPageBodyWidth(page);
    IContainerArea pageBody=page.getBody();
    int definedBodyHeight=0;
    int definedBodyWidth=0;
    if (pageBody != null) {
      definedBodyHeight=pageBody.getHeight();
      definedBodyWidth=pageBody.getWidth();
    }
    if (pageBodyHeight > definedBodyHeight) {
      addExtendDirection(EXTEND_ON_VERTICAL);
    }
    if (pageBodyWidth > definedBodyWidth) {
      addExtendDirection(EXTEND_ON_HORIZONTAL);
    }
    offsetX=0;
    offsetY=0;
    if (extendDirection == EXTEND_NONE) {
      addPage(page);
    }
 else     if (extendDirection == EXTEND_ON_HORIZONTAL) {
      do {
        addPage(page);
        offsetX+=definedBodyWidth;
      }
 while (offsetX < pageBodyWidth - ignoredOverflow);
    }
 else     if (extendDirection == EXTEND_ON_VERTICAL) {
      do {
        addPage(page);
        offsetY+=definedBodyHeight;
      }
 while (offsetY < pageBodyHeight - ignoredOverflow);
    }
 else     if (extendDirection == EXTEND_ON_HORIZONTAL_AND_VERTICAL) {
      do {
        do {
          addPage(page);
          offsetX+=definedBodyWidth;
        }
 while (offsetX < pageBodyWidth - ignoredOverflow);
        offsetX=0;
        offsetY+=definedBodyHeight;
      }
 while (offsetY < pageBodyHeight - ignoredOverflow);
    }
    setExtendDirection(EXTEND_NONE);
  }
 else {
    addPage(page);
  }
}