[
https://issues.apache.org/jira/browse/FOP-3323?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Joao Goncalves resolved FOP-3323.
---------------------------------
Fix Version/s: main
Resolution: Fixed
https://github.com/apache/xmlgraphics-fop/commit/8e4a19cf214ddfc27ad1d03fa04a14e717f6ce0a
> NPE in layout manager when `fo:title` carries an `id` attribute —
> `Page.getPageViewport()` on null `this.curPage`
> -----------------------------------------------------------------------------------------------------------------
>
> Key: FOP-3323
> URL: https://issues.apache.org/jira/browse/FOP-3323
> Project: FOP
> Issue Type: Bug
> Components: layout/unqualified, renderer/pdf
> Affects Versions: 2.11
> Reporter: Martin Leitner
> Priority: Minor
> Fix For: main
>
> Attachments: no-title.fo, title-no-id.fo, title-with-id.fo
>
>
> *Description*
> FOP throws a {{NullPointerException}} in the layout manager when a
> {{fo:title}} element carries an {{id}} attribute. The failure happens while
> wiring the per-page ID->element map: {{Page.getPageViewport()}} is invoked on
> {{{}this.curPage{}}}, which is still {{null}} because {{fo:title}} is
> processed at {{fo:page-sequence}} scope, before any page has been constructed.
>
> {code:java}
> java.lang.NullPointerException: Cannot invoke
> "org.apache.fop.layoutmgr.Page.getPageViewport()" because "this.curPage" is
> null{code}
> Note: {{fo:title}} is _not permitted_ to carry {{id}} per XSL-FO 1.1 §6.4.20
> (its allowed properties do not include the {{id}} property). So this is
> invalid FO input. The request here is not to _accept_ the {{{}id{}}}, but for
> FOP to fail gracefully (validation error / skipped registration) instead of
> NPE-ing. This is consistent with the existing documented limitation on the
> Known Issues page ("the 'id' attributes are not properly handled for all
> block-level / inline-level FO elements").
> *Steps to reproduce*
> Three sibling FO files isolate the trigger. They are identical except for the
> presence of {{fo:title}} and its {{{}id{}}}.
> # title-with-id.fo: triggers the NPE
> # title-no-id.fo: renders OK (same file, {{id}} removed from
> {{{}fo:title{}}})
> # no-title.fo: renders OK (same file, {{fo:title}} removed entirely)
> Run each:
>
> {code:java}
> fop -fo title-with-id.fo -pdf out.pdf
> {code}
>
> ||Input ||Result ||
> |no-title.fo|OK - renders to PDF |
> |title-no-id.fo|OK - renders to PDF |
> |title-with-id.fo|NPE - {{Page.getPageViewport()}} on null {{this.curPage}}|
> File 1 differs from file 2 only by {{id="t1"}} on {{{}fo:title{}}}.
>
> *Expected*
> Either a clean validation error ("property 'id' is not applicable to
> fo:title") or silently skip ID registration for {{{}fo:title{}}}. No
> {{{}NullPointerException{}}}.
> *Actual*
> Uncaught {{NullPointerException}} from the layout manager; processing aborts.
> *Suggested fix*
> * AreaTreeHandler / PageSequenceLayoutManager - defer wiring fo:title/@id
> into the ID->element map until the first page is constructed, _or_ skip ID
> registration for fo:title (it lives outside any page viewport).
> * Defensive guard on {{this.curPage == null}} before the
> Page.getPageViewport() call.
>
--
This message was sent by Atlassian Jira
(v8.20.10#820010)