Skip to content

NullPointerException in Xerces when Match.transform() doesn't produce any nodes #166

@lukaseder

Description

@lukaseder

When using Match.transform(), we can get NullPointerException when the argument XSL does not produce any nodes

Consider this program:

public static void main(String[] args) throws Exception {
    Match xml = JOOX.$(QOM.class.getResourceAsStream("/xml.xml"));
    System.out.println(xml);

    Match result = xml.transform(QOM.class.getResourceAsStream("/xsl.xsl"));
    System.out.println(result);
}

And the stylesheet might have no templates that match, e.g.

<xsl:stylesheet version="2.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

    <xsl:output encoding="UTF-8" method="html" omit-xml-declaration="yes" indent="yes"/>
</xsl:stylesheet>

Then, this will be the result:

Exception in thread "main" java.lang.NullPointerException
	at java.xml/com.sun.org.apache.xerces.internal.dom.CoreDocumentImpl.importNode(CoreDocumentImpl.java:1536)
	at java.xml/com.sun.org.apache.xerces.internal.dom.CoreDocumentImpl.importNode(CoreDocumentImpl.java:1501)
	at org.joox.Impl.transform(Impl.java:1889)
	at org.joox.Impl.transform(Impl.java:1900)
	at org.joox.Impl.transform(Impl.java:1909)
	at org.joox.Impl.transform(Impl.java:79)
	at org.jooq.qom.QOM.main(QOM.java:49)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions