[jira] [Created] (FOP-3323) NPE in layout manager when `fo:title` carr ies an `id` attribute — `Page.getPa geViewport()` on null `this.curPage`
"Martin Leitner (Jira)" <[email protected]> Fri, 5 Jun 2026 09:28:00 +0000 (UTC)
| Newsgroups | gmane.text.xml.fop.devel |
|---|---|
| Message-ID | <[email protected]> |
Martin Leitner created FOP-3323:
-----------------------------------
Summary: 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
Attachments: no-title.fo, title-no-id.fo, title-with-id.fo
*Description*
FOP throws a {{NullPointerException}} in the layout manager when a {{fo:tit=
le}} 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.
=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=A7=
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{}}}, b=
ut for FOP to fail gracefully (validation error / skipped registration) ins=
tead of NPE-ing. This is consistent with the existing documented limitation=
on the Known Issues page ("the 'id' attributes are not properly handled fo=
r all block-level / inline-level FO elements").
*Steps to reproduce*
Three sibling FO files isolate the trigger. They are identical except for t=
he 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}}=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:tit=
le") or silently skip ID registration for {{{}fo:title{}}}. No {{{}NullPoin=
terException{}}}.
*Actual*
Uncaught {{NullPointerException}}=C2=A0from 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 =3D=3D null}} before the Page.getPageV=
iewport() call.
=C2=A0
--
This message was sent by Atlassian Jira
(v8.20.10#820010)