[jira] [Resolved] (FOP-3323) NPE in layout manager when `fo:title` carr ies an `id` attribute — `Page.getPa geViewport()` on null `this.curPage`
"Joao Goncalves (Jira)" <[email protected]> Thu, 25 Jun 2026 16:52:00 +0000 (UTC)
| Newsgroups | gmane.text.xml.fop.devel |
|---|---|
| Message-ID | <[email protected]> |
[ https://issues.apache.org/jira/browse/FOP-3323?page=3Dcom.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/8e4a19cf214ddfc27ad1d03fa0=
4a14e717f6ce0a
> NPE in layout manager when `fo:title` carries an `id` attribute =E2=80=94=
`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:t=
itle}} element carries an {{id}} attribute. The failure happens while wirin=
g the per-page ID->element map: {{Page.getPageViewport()}} is invoked on {{=
{}this.curPage{}}}, which is still {{null}} because {{fo:title}} is process=
ed at {{fo:page-sequence}} scope, before any page has been constructed.
> =C2=A0
> {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 =C2=
=A76.4.20 (its allowed properties do not include the {{id}} property). So t=
his 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 limitat=
ion 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:titl=
e{}}})
> # no-title.fo: renders OK (same file, {{fo:title}}=C2=A0removed entirely=
)
> Run each:
> =C2=A0
> {code:java}
> fop -fo title-with-id.fo -pdf out.pdf
> {code}
> =C2=A0
> ||Input=C2=A0||Result=C2=A0||
> |no-title.fo|OK - renders to PDF=C2=A0|
> |title-no-id.fo|OK - renders to PDF=C2=A0|
> |title-with-id.fo|NPE - {{Page.getPageViewport()}} on null {{this.curPage=
}}|
> File 1 differs from file 2 only by {{id=3D"t1"}} on {{{}fo:title{}}}.
> =C2=A0
> *Expected*
> Either a clean validation error ("property 'id' is not applicable to fo:t=
itle") or silently skip ID registration for {{{}fo:title{}}}. No {{{}NullPo=
interException{}}}.
> *Actual*
> Uncaught {{NullPointerException}}=C2=A0from the layout manager; processin=
g aborts.
> *Suggested fix*
> * AreaTreeHandler / PageSequenceLayoutManager - defer wiring fo:title/@i=
d into the ID->element map until the first page is constructed, _or_ skip I=
D registration for fo:title (it lives outside any page viewport).
> * Defensive guard on {{this.curPage =3D=3D null}} before the Page.getPag=
eViewport() call.
> =C2=A0
--
This message was sent by Atlassian Jira
(v8.20.10#820010)