Bug #2415
closedNullPointerException processing DOM with null nodeValue
100%
Description
Processing the following XML:
<testDetailSummary>
<testReference>Test</testReference>
<testSummary>
</testSummary>
<softwareBuild warning="no">BUILD</softwareBuild>
<startTime>Wed Jul 8 16:14:55 IST 2015</startTime>
<endTime>Wed Jul 8 16:16:51 IST 2015</endTime>
</testDetailSummary>
with the following XSLT:
<xsl:for-each select="owr/testDetailSummary/*">
<xsl:message>Processing test summary</xsl:message>
<li>
<b>
<xsl:choose>
<xsl:when test="local-name() = 'testReference'">
<xsl:message>Processing test ref</xsl:message>
<xsl:text>Test Reference: </xsl:text>
</xsl:when>
<xsl:when test="local-name() = 'testSummary'">
<xsl:message>Processing test summary</xsl:message>
<xsl:text>Test Summary: </xsl:text>
</xsl:when>
<xsl:when test="local-name() = 'startTime'">
<xsl:message>Processing start time</xsl:message>
<xsl:text>Test Start Time: </xsl:text>
</xsl:when>
<xsl:when test="local-name() = 'endTime'">
<xsl:message>Processing end time</xsl:message>
<xsl:text>Test End Time: </xsl:text>
</xsl:when>
<xsl:when test="local-name() = 'softwareBuild'">
<xsl:message>Processing software build</xsl:message>
<xsl:text>Software Build: </xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="local-name()"/>
<xsl:message>Processing none of testDetailSummary</xsl:message>
<xsl:text>: </xsl:text>
</xsl:otherwise>
</xsl:choose>
</b>
<xsl:value-of select="."/>
</li>
</xsl:for-each>
With the following output:
Processing test summary
Processing test ref
Processing test summary
Processing test summary
Produces the following exception:
2015-07-09 14:43:07.901 ERROR XMLToHTML applyStylesheet(...) - applyStylesheet: java.lang.RuntimeException: Internal error evaluating template at line 1 in module
java.lang.RuntimeException: Internal error evaluating template at line 1 in module
at net.sf.saxon.expr.instruct.Template.applyLeavingTail(Template.java:349)
at net.sf.saxon.trans.Mode.applyTemplates(Mode.java:1124)
at net.sf.saxon.Controller.transformDocument(Controller.java:2106)
at net.sf.saxon.Controller.transform(Controller.java:1705)
at net.sf.saxon.s9api.XsltTransformer.transform(XsltTransformer.java:547)
at net.sf.saxon.jaxp.TransformerImpl.transform(TransformerImpl.java:177)
Caused by: java.lang.NullPointerException
at net.sf.saxon.tree.util.FastStringBuffer.append(FastStringBuffer.java:68)
at net.sf.saxon.dom.DOMNodeWrapper.expandStringValue(DOMNodeWrapper.java:337)
at net.sf.saxon.dom.DOMNodeWrapper.getStringValueCS(DOMNodeWrapper.java:283)
at net.sf.saxon.tree.wrapper.AbstractNodeWrapper.atomize(AbstractNodeWrapper.java:104)
at net.sf.saxon.expr.Atomizer.evaluateItem(Atomizer.java:318)
at net.sf.saxon.expr.Atomizer.evaluateItem(Atomizer.java:35)
at net.sf.saxon.expr.AtomicSequenceConverter.evaluateItem(AtomicSequenceConverter.java:275)
at net.sf.saxon.expr.AtomicSequenceConverter.evaluateItem(AtomicSequenceConverter.java:30)
at net.sf.saxon.expr.Expression.evaluateAsString(Expression.java:524)
at net.sf.saxon.expr.instruct.SimpleNodeConstructor.processLeavingTail(SimpleNodeConstructor.java:216)
at net.sf.saxon.expr.instruct.ValueOf.processLeavingTail(ValueOf.java:280)
at net.sf.saxon.expr.instruct.Block.processLeavingTail(Block.java:669)
at net.sf.saxon.expr.instruct.Instruction.process(Instruction.java:144)
at net.sf.saxon.expr.instruct.ElementCreator.processLeavingTail(ElementCreator.java:450)
at net.sf.saxon.expr.instruct.ElementCreator.processLeavingTail(ElementCreator.java:389)
at net.sf.saxon.expr.instruct.Block.processLeavingTail(Block.java:669)
at net.sf.saxon.expr.instruct.Instruction.process(Instruction.java:144)
at net.sf.saxon.expr.instruct.ForEach.processLeavingTail(ForEach.java:419)
at net.sf.saxon.expr.instruct.Instruction.process(Instruction.java:144)
at net.sf.saxon.expr.instruct.ElementCreator.processLeavingTail(ElementCreator.java:450)
at net.sf.saxon.expr.instruct.ElementCreator.processLeavingTail(ElementCreator.java:389)
at net.sf.saxon.expr.instruct.Block.processLeavingTail(Block.java:669)
at net.sf.saxon.expr.instruct.Instruction.process(Instruction.java:144)
at net.sf.saxon.expr.instruct.ElementCreator.processLeavingTail(ElementCreator.java:450)
at net.sf.saxon.expr.instruct.ElementCreator.processLeavingTail(ElementCreator.java:389)
at net.sf.saxon.expr.instruct.Block.processLeavingTail(Block.java:669)
at net.sf.saxon.expr.instruct.Instruction.process(Instruction.java:144)
at net.sf.saxon.expr.instruct.ElementCreator.processLeavingTail(ElementCreator.java:450)
at net.sf.saxon.expr.instruct.ElementCreator.processLeavingTail(ElementCreator.java:389)
at net.sf.saxon.expr.instruct.Block.processLeavingTail(Block.java:669)
at net.sf.saxon.expr.instruct.Template.expand(Template.java:367)
at net.sf.saxon.expr.instruct.CallTemplate.process(CallTemplate.java:343)
at net.sf.saxon.expr.instruct.CallTemplate.processLeavingTail(CallTemplate.java:397)
at net.sf.saxon.expr.instruct.Block.processLeavingTail(Block.java:669)
at net.sf.saxon.expr.instruct.Instruction.process(Instruction.java:144)
at net.sf.saxon.expr.instruct.ElementCreator.processLeavingTail(ElementCreator.java:450)
at net.sf.saxon.expr.instruct.ElementCreator.processLeavingTail(ElementCreator.java:389)
at net.sf.saxon.expr.instruct.Block.processLeavingTail(Block.java:669)
at net.sf.saxon.expr.instruct.Instruction.process(Instruction.java:144)
at net.sf.saxon.expr.instruct.ElementCreator.processLeavingTail(ElementCreator.java:450)
at net.sf.saxon.expr.instruct.ElementCreator.processLeavingTail(ElementCreator.java:389)
at net.sf.saxon.expr.instruct.Block.processLeavingTail(Block.java:669)
at net.sf.saxon.expr.instruct.Instruction.process(Instruction.java:144)
at net.sf.saxon.expr.instruct.ElementCreator.processLeavingTail(ElementCreator.java:450)
at net.sf.saxon.expr.instruct.ElementCreator.processLeavingTail(ElementCreator.java:389)
at net.sf.saxon.expr.instruct.Block.processLeavingTail(Block.java:669)
at net.sf.saxon.expr.instruct.Instruction.process(Instruction.java:144)
at net.sf.saxon.expr.instruct.ElementCreator.processLeavingTail(ElementCreator.java:450)
at net.sf.saxon.expr.instruct.ElementCreator.processLeavingTail(ElementCreator.java:389)
at net.sf.saxon.expr.instruct.Block.processLeavingTail(Block.java:669)
at net.sf.saxon.expr.instruct.Instruction.process(Instruction.java:144)
at net.sf.saxon.expr.instruct.ElementCreator.processLeavingTail(ElementCreator.java:450)
at net.sf.saxon.expr.instruct.ElementCreator.processLeavingTail(ElementCreator.java:389)
at net.sf.saxon.expr.instruct.Instruction.process(Instruction.java:144)
at net.sf.saxon.expr.instruct.ElementCreator.processLeavingTail(ElementCreator.java:450)
at net.sf.saxon.expr.instruct.ElementCreator.processLeavingTail(ElementCreator.java:389)
at net.sf.saxon.expr.instruct.Block.processLeavingTail(Block.java:669)
at net.sf.saxon.expr.instruct.Instruction.process(Instruction.java:144)
at net.sf.saxon.expr.instruct.ElementCreator.processLeavingTail(ElementCreator.java:450)
at net.sf.saxon.expr.instruct.ElementCreator.processLeavingTail(ElementCreator.java:389)
at net.sf.saxon.expr.instruct.Template.applyLeavingTail(Template.java:336)
... 10 more
Updated by John Lawlor over 9 years ago
tag is empty, if it is populated, the issue goes away.
Updated by John Lawlor over 9 years ago
Sorry, the XSLT is a bit confusing since I have used the same xsl:message in two places. The error occurs here - specifically:
<xsl:when test="local-name() = 'testSummary'">
<xsl:message>Processing test summary</xsl:message>
<xsl:text>Test Summary: </xsl:text>
</xsl:when>
Updated by Michael Kay over 9 years ago
- Project changed from Saxon-CE to Saxon
- Category set to DOM Interface
- Priority changed from Low to Normal
- Found in version changed from Saxon-HE-9.6.0-5.jar to 9.6
I don't see any obvious resemblance to bug #2160. It looks much more like a repeat of #2407.
I had previously closed 2407 with no action on the grounds that it appeared someone had built an invalid DOM and there's no way we can cope with that. But if the same thing has happened again independently, then we need to look more carefully.
The stack trace shows that your input to this transformation is a DOM tree, and the exception suggests that the DOM tree contains a text node whose string value is null. How did you construct the DOM? Is there any explanation for the string value being null?
(I hope you are aware that using a DOM as input can be ten times slower than using Saxon's native tree format.)
Updated by John Lawlor over 9 years ago
Hi Michael,
I think the bug is on our side. We should not be creating an empty tag. DOM is constructed using standard w3c java libraries and then the conversion is run as follows:
try {
LOGGER.info("Creating document builder document");
document = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
LOGGER.info("Creating dom result");
DOMResult result = new DOMResult(document);
LOGGER.info("Running transform");
this.xsltTransformer.transform(new DOMSource(this.sourceDocument), result);
} catch (Exception ex) {
LOGGER.error("applyStylesheet: " + ex.toString());
ex.printStackTrace();
document = null;
}
No, I didn't realise that is was 10 times slower. The XSLT part of our application is the fastest so it didn't get much attention.
Updated by Michael Kay over 9 years ago
- Status changed from New to Resolved
I've noticed that on other paths we're careful to check whether node.getNodeValue() returns null, whether or not the documentation says this is possible; so I've added the same check to this path.
Patched on the 9.6 and 9.7 branches.
Updated by O'Neil Delpratt over 9 years ago
- Status changed from Resolved to Closed
- % Done changed from 0 to 100
- Fixed in version set to 9.6.0.7
Bug fix applied in the Saxon 9.6.0.7 maintenance release.
Updated by O'Neil Delpratt almost 9 years ago
- Applies to branch 9.6 added
- Fix Committed on Branch 9.6 added
- Fixed in Maintenance Release 9.6.0.7 added
Updated by Michael Kay over 8 years ago
- Subject changed from Error found in Issue #2160 appearing in Saxon-HE-9.6.0-5 to NullPointerException processing DOM with null nodeValue
Please register to edit this issue