Program: 71671
Project: 71671
Buggy source:
protected void resolveTotalPage(IContentEmitter emitter){
  IContent con=context.getUnresolvedContent();
  if (!(con instanceof IAutoTextContent)) {
    return;
  }
  IAutoTextContent totalPageContent=(IAutoTextContent)con;
  if (null != totalPageContent) {
    NumberFormatter nf=new NumberFormatter();
    String patternStr=totalPageContent.getComputedStyle().getNumberFormat();
    nf.applyPattern(patternStr);
    long totalPageCount=0;
    if (context.autoPageBreak) {
      totalPageCount=context.pageCount;
    }
 else {
      totalPageCount=context.totalPage > 0 ? context.totalPage : context.pageCount;
    }
    totalPageContent.setText(nf.format(totalPageCount));
    AbstractArea totalPageArea=null;
    ChunkGenerator cg=new ChunkGenerator(context.getFontManager(),totalPageContent,true,true);
    if (cg.hasMore()) {
      Chunk c=cg.getNext();
      Dimension d=new Dimension((int)(c.getFontInfo().getWordWidth(c.getText()) * PDFConstants.LAYOUT_TO_PDF_RATIO),(int)(c.getFontInfo().getWordHeight() * PDFConstants.LAYOUT_TO_PDF_RATIO));
      totalPageArea=(AbstractArea)AreaFactory.createTextArea(totalPageContent,c.getFontInfo(),false);
      totalPageArea.setWidth(Math.min(context.getMaxWidth(),d.getWidth()));
      totalPageArea.setHeight(Math.min(context.getMaxHeight(),d.getHeight()));
    }
    String align=totalPageContent.getComputedStyle().getTextAlign();
    if ((CSSConstants.CSS_RIGHT_VALUE.equalsIgnoreCase(align) || CSSConstants.CSS_CENTER_VALUE.equalsIgnoreCase(align))) {
      int spacing=context.getTotalPageTemplateWidth() - totalPageArea.getWidth();
      if (spacing > 0) {
        if (CSSConstants.CSS_RIGHT_VALUE.equalsIgnoreCase(align)) {
          totalPageArea.setAllocatedPosition(spacing + totalPageArea.getAllocatedX(),totalPageArea.getAllocatedY());
        }
 else         if (CSSConstants.CSS_CENTER_VALUE.equalsIgnoreCase(align)) {
          totalPageArea.setAllocatedPosition(spacing / 2 + totalPageArea.getAllocatedX(),totalPageArea.getAllocatedY());
        }
      }
    }
    totalPageContent.setExtension(IContent.LAYOUT_EXTENSION,totalPageArea);
    emitter.startAutoText(totalPageContent);
  }
}

Fixed version (ground truth):
protected void resolveTotalPage(IContentEmitter emitter){
  IContent con=context.getUnresolvedContent();
  if (!(con instanceof IAutoTextContent)) {
    return;
  }
  IAutoTextContent totalPageContent=(IAutoTextContent)con;
  if (null != totalPageContent) {
    NumberFormatter nf=new NumberFormatter();
    String patternStr=totalPageContent.getComputedStyle().getNumberFormat();
    nf.applyPattern(patternStr);
    long totalPageCount=0;
    if (context.autoPageBreak) {
      totalPageCount=context.pageCount;
    }
 else {
      totalPageCount=context.totalPage > 0 ? context.totalPage : context.pageCount;
    }
    totalPageContent.setText(nf.format(totalPageCount));
    AbstractArea totalPageArea=null;
    ChunkGenerator cg=new ChunkGenerator(context.getFontManager(),totalPageContent,true,true);
    if (cg.hasMore()) {
      Chunk c=cg.getNext();
      Dimension d=new Dimension((int)(c.getFontInfo().getWordWidth(c.getText()) * PDFConstants.LAYOUT_TO_PDF_RATIO),(int)(c.getFontInfo().getWordHeight() * PDFConstants.LAYOUT_TO_PDF_RATIO));
      totalPageArea=(AbstractArea)AreaFactory.createTextArea(totalPageContent,c.getFontInfo(),false);
      totalPageArea.setWidth(Math.min(context.getMaxWidth(),d.getWidth()));
      totalPageArea.setHeight(Math.min(context.getMaxHeight(),d.getHeight()));
    }
    String align=totalPageContent.getComputedStyle().getTextAlign();
    boolean isRightAligned=BidiAlignmentResolver.isRightAligned(totalPageContent,align,false);
    if ((isRightAligned || CSSConstants.CSS_CENTER_VALUE.equalsIgnoreCase(align))) {
      int spacing=context.getTotalPageTemplateWidth() - totalPageArea.getWidth();
      if (spacing > 0) {
        if (isRightAligned) {
          totalPageArea.setAllocatedPosition(spacing + totalPageArea.getAllocatedX(),totalPageArea.getAllocatedY());
        }
 else         if (CSSConstants.CSS_CENTER_VALUE.equalsIgnoreCase(align)) {
          totalPageArea.setAllocatedPosition(spacing / 2 + totalPageArea.getAllocatedX(),totalPageArea.getAllocatedY());
        }
      }
    }
    totalPageContent.setExtension(IContent.LAYOUT_EXTENSION,totalPageArea);
    emitter.startAutoText(totalPageContent);
  }
}