Program: 67591
Project: 67591
Buggy source:
protected void resolveTotalPage(IContentEmitter emitter) throws BirtException {
  IContent con=context.getUnresolvedContent();
  if (!(con instanceof IAutoTextContent)) {
    return;
  }
  IAutoTextContent totalPageContent=(IAutoTextContent)con;
  if (null != totalPageContent) {
    DataFormatValue format=totalPageContent.getComputedStyle().getDataFormat();
    NumberFormatter nf=null;
    if (format == null) {
      nf=new NumberFormatter();
    }
 else {
      String pattern=format.getNumberPattern();
      String locale=format.getNumberLocale();
      if (locale == null)       nf=new NumberFormatter(pattern);
 else       nf=new NumberFormatter(pattern,new ULocale(locale));
    }
    long totalPageCount=0;
    if (context.isReserveDocumentPageNumbers()) {
      totalPageCount=context.totalPage;
    }
 else {
      totalPageCount=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=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.setPosition(spacing + totalPageArea.getX(),totalPageArea.getY());
        }
 else         if (CSSConstants.CSS_CENTER_VALUE.equalsIgnoreCase(align)) {
          totalPageArea.setPosition(spacing / 2 + totalPageArea.getX(),totalPageArea.getY());
        }
      }
    }
    totalPageContent.setExtension(IContent.LAYOUT_EXTENSION,totalPageArea);
    emitter.startAutoText(totalPageContent);
  }
}

Fixed version (ground truth):
protected void resolveTotalPage(IContentEmitter emitter) throws BirtException {
  IContent con=context.getUnresolvedContent();
  if (!(con instanceof IAutoTextContent)) {
    return;
  }
  IAutoTextContent totalPageContent=(IAutoTextContent)con;
  if (null != totalPageContent) {
    DataFormatValue format=totalPageContent.getComputedStyle().getDataFormat();
    NumberFormatter nf=null;
    if (format == null) {
      nf=new NumberFormatter();
    }
 else {
      String pattern=format.getNumberPattern();
      String locale=format.getNumberLocale();
      if (locale == null)       nf=new NumberFormatter(pattern);
 else       nf=new NumberFormatter(pattern,new ULocale(locale));
    }
    totalPageContent.setText(nf.format(context.pageCount));
    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=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.setPosition(spacing + totalPageArea.getX(),totalPageArea.getY());
        }
 else         if (CSSConstants.CSS_CENTER_VALUE.equalsIgnoreCase(align)) {
          totalPageArea.setPosition(spacing / 2 + totalPageArea.getX(),totalPageArea.getY());
        }
      }
    }
    totalPageContent.setExtension(IContent.LAYOUT_EXTENSION,totalPageArea);
    emitter.startAutoText(totalPageContent);
  }
}