From 1317b5529ca1435fc3f3ecb89b32f8fc237975a5 Mon Sep 17 00:00:00 2001 From: Simon Steiner Date: Thu, 8 Dec 2022 13:04:53 +0000 Subject: [PATCH] FOP-3110: NPE if link destination is missing with accessibility git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1905858 13f79535-47bb-0310-9956-ffa450edef68 --- .../fop/render/intermediate/IFSerializer.java | 7 ++- .../fop/intermediate/AbstractIFTest.java | 21 +++++++- ...basic-link_internal-desination-missing.xml | 52 +++++++++++++++++++ 3 files changed, 77 insertions(+), 3 deletions(-) create mode 100644 fop/test/intermediate/basic-link_internal-desination-missing.xml diff --git a/fop-core/src/main/java/org/apache/fop/render/intermediate/IFSerializer.java b/fop-core/src/main/java/org/apache/fop/render/intermediate/IFSerializer.java index ee6557d43..0bdcb0626 100644 --- a/fop-core/src/main/java/org/apache/fop/render/intermediate/IFSerializer.java +++ b/fop-core/src/main/java/org/apache/fop/render/intermediate/IFSerializer.java @@ -914,8 +914,11 @@ implements IFConstants, IFPainter, IFDocumentNavigationHandler { atts.addAttribute("", "rect", "rect", XMLConstants.CDATA, IFUtil.toString(link.getTargetRect())); if (getUserAgent().isAccessibilityEnabled()) { - addStructRefAttribute(atts, - ((IFStructureTreeElement) link.getAction().getStructureTreeElement()).getId()); + IFStructureTreeElement structureTreeElement = + (IFStructureTreeElement) link.getAction().getStructureTreeElement(); + if (structureTreeElement != null) { + addStructRefAttribute(atts, structureTreeElement.getId()); + } } try { handler.startElement(DocumentNavigationExtensionConstants.LINK, atts); diff --git a/fop-core/src/test/java/org/apache/fop/intermediate/AbstractIFTest.java b/fop-core/src/test/java/org/apache/fop/intermediate/AbstractIFTest.java index 48c3f335b..9e412a272 100644 --- a/fop-core/src/test/java/org/apache/fop/intermediate/AbstractIFTest.java +++ b/fop-core/src/test/java/org/apache/fop/intermediate/AbstractIFTest.java @@ -32,6 +32,10 @@ import javax.xml.transform.sax.SAXResult; import javax.xml.validation.Schema; import javax.xml.validation.SchemaFactory; import javax.xml.validation.Validator; +import javax.xml.xpath.XPath; +import javax.xml.xpath.XPathConstants; +import javax.xml.xpath.XPathExpressionException; +import javax.xml.xpath.XPathFactory; import org.w3c.dom.Document; import org.xml.sax.ErrorHandler; @@ -105,6 +109,7 @@ abstract class AbstractIFTest extends AbstractIntermediateTest { DOMResult domResult = new DOMResult(); FOUserAgent userAgent = createUserAgent(); + userAgent.setAccessibility(isAccessibility(testDoc)); //Create an instance of the target renderer so the XMLRenderer can use its font setup IFDocumentHandler targetHandler = userAgent.getRendererFactory().createDocumentHandler( @@ -124,9 +129,23 @@ abstract class AbstractIFTest extends AbstractIntermediateTest { return (Document) domResult.getNode(); } + private boolean isAccessibility(Document testDoc) { + try { + String s = eval(testDoc, "/testcase/cfg/accessibility"); + return "true".equals(s); + } catch (XPathExpressionException e) { + throw new RuntimeException(e); + } + } + + private String eval(Document doc, String xpath) throws XPathExpressionException { + XPath xPath = XPathFactory.newInstance().newXPath(); + return (String) xPath.compile(xpath).evaluate(doc, XPathConstants.STRING); + } + @Override protected void validate(Document doc) throws SAXException, IOException { - if (IF_SCHEMA == null) { + if (IF_SCHEMA == null || isAccessibility(testDoc)) { return; //skip validation; } Validator validator = IF_SCHEMA.newValidator(); diff --git a/fop/test/intermediate/basic-link_internal-desination-missing.xml b/fop/test/intermediate/basic-link_internal-desination-missing.xml new file mode 100644 index 000000000..7b089037b --- /dev/null +++ b/fop/test/intermediate/basic-link_internal-desination-missing.xml @@ -0,0 +1,52 @@ + + + + + +

+ This test checks a fo:basic-link in a span +

+
+ + true + + + + + + + + + + + + + + + + + SECTION 1 Introduction + + + + + + + + +
-- 2.39.5