Bug #2815
closedNullPointerException with Saxon EE 9.7.0.6 with stylesheet using xsl:merge
100%
Description
https://www.data2type.de/xml-xslt-xslfo/xslt/xslt3/ has some XSLT 3.0 stylesheets that seem to be developed with Saxon 9.6. Yesterday I tried some of them with Saxon 9.7 and I run into a problem with the samples in https://www.data2type.de/xml-xslt-xslfo/xslt/xslt3/streaming/loesungen/uebung7-mitarbeiterlisten/, Saxon 9.7 EE gives a NullPointerException when compiling the stylesheet.
As the original code uses a collection of input files I tried to reduce the sample, the reduced test case is
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs" version="3.0">
<xsl:output indent="yes" />
<xsl:strip-space elements="*" />
<xsl:mode on-no-match="shallow-copy" />
<xsl:template match="/" name="main">
<Personenliste>
<xsl:merge>
<xsl:merge-source for-each-stream="'input1.xml'" streamable="yes" select="Company/Person/Name">
<xsl:merge-key select="Surname" />
</xsl:merge-source>
<xsl:merge-action>
<xsl:apply-templates select="current-merge-group()" />
</xsl:merge-action>
</xsl:merge>
</Personenliste>
</xsl:template>
<xsl:template match="Name">
<Person>
<xsl:attribute name="Firma" select="ancestor::Company/@Name"></xsl:attribute>
<xsl:apply-templates select="node()" />
</Person>
</xsl:template>
<xsl:template match="Surname">
<Nachname>
<xsl:apply-templates select="node()" />
</Nachname>
</xsl:template>
<xsl:template match="Firstname">
<Vorname>
<xsl:apply-templates select="node()" />
</Vorname>
</xsl:template>
</xsl:stylesheet>
a minimal input file is
<?xml version="1.0" encoding="UTF-8"?>
<Company Name="Company A">
<Person>
<Name Title="Mr." Gender="male">
<Firstname>John</Firstname>
<Surname>Doe</Surname>
</Name>
</Person>
</Company>
when I run Saxon-EE 9.7.0.6J from the command line with -t -xsl:.\sheet2.xsl -it:main
it outputs the following stack trace:
java.lang.NullPointerException
at com.saxonica.xslt3.instruct.MergeInstr$MergeSource.copy(MergeInstr.java:108)
at com.saxonica.xslt3.instruct.MergeInstr.copy(MergeInstr.java:688)
at net.sf.saxon.expr.instruct.FixedElement.copy(FixedElement.java:228)
at net.sf.saxon.style.XSLTemplate.optimize(XSLTemplate.java:808)
at net.sf.saxon.style.PrincipalStylesheetModule.optimizeTopLevel(PrincipalStylesheetModule.java:1349)
at net.sf.saxon.style.PrincipalStylesheetModule.compile(PrincipalStylesheetModule.java:1199)
at net.sf.saxon.style.Compilation.compilePackage(Compilation.java:262)
at net.sf.saxon.style.StylesheetModule.loadStylesheet(StylesheetModule.java:260)
at net.sf.saxon.style.Compilation.compileSingletonPackage(Compilation.java:101)
at net.sf.saxon.s9api.XsltCompiler.compile(XsltCompiler.java:859)
at net.sf.saxon.Transform.doTransform(Transform.java:727)
at net.sf.saxon.Transform.main(Transform.java:77)
Saxon-EE 9.6.0.9J runs the code and outputs the result
<?xml version="1.0" encoding="UTF-8"?>
<Personenliste>
<Person Firma="Company A">
<Vorname>John</Vorname>
<Nachname>Doe</Nachname>
</Person>
</Personenliste>
Files
Updated by Michael Kay over 8 years ago
- Category set to Internals
- Status changed from New to Resolved
- Assignee set to Michael Kay
- Priority changed from Low to High
- Applies to branch 9.7, 9.8 added
- Fix Committed on Branch 9.7, 9.8 added
The optimizer has decided to extract the xsl:merge instruction into a global variable, which requires copying the instruction, and it seems that copying of xsl:merge instructions (in which some operands may legitimately be absent) has not been well tested.
Added this as test case merge-090.
Patch produced for 9.7 and 9.8 branches.
Updated by Martin Honnen over 8 years ago
I have another reduced xsl:merge test case that also results in a NullPointerException, with a slightly different stack trace: XSLT is
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:math="http://www.w3.org/2005/xpath-functions/math" exclude-result-prefixes="xs math"
version="3.0">
<xsl:template name="main">
<xsl:variable name="seq1" as="xs:integer*">
<xsl:merge>
<xsl:merge-source select="1 to 30">
<xsl:merge-key select="."/>
</xsl:merge-source>
<xsl:merge-source select="20 to 40">
<xsl:merge-key select="."/>
</xsl:merge-source>
<xsl:merge-action>
<xsl:sequence select="current-merge-key()"/>
</xsl:merge-action>
</xsl:merge>
</xsl:variable>
<xsl:value-of select="$seq1"/>
</xsl:template>
</xsl:stylesheet>
The stack trace generated by Saxon EE 9.7.0.6 is
java.lang.NullPointerException
at com.saxonica.xslt3.instruct.MergeInstr$MergeSource.copy(MergeInstr.java:108)
at com.saxonica.xslt3.instruct.MergeInstr.copy(MergeInstr.java:688)
at net.sf.saxon.expr.UntypedSequenceConverter.copy(UntypedSequenceConverter.java:165)
at net.sf.saxon.expr.ItemChecker.copy(ItemChecker.java:267)
at net.sf.saxon.expr.LetExpression.inlineReferences(LetExpression.java:352)
at net.sf.saxon.expr.LetExpression.optimize(LetExpression.java:291)
at net.sf.saxon.expr.parser.ExpressionTool.optimizeComponentBody(ExpressionTool.java:1078)
at net.sf.saxon.style.XSLTemplate.optimize(XSLTemplate.java:795)
at net.sf.saxon.style.PrincipalStylesheetModule.optimizeTopLevel(PrincipalStylesheetModule.java:1349)
at net.sf.saxon.style.PrincipalStylesheetModule.compile(PrincipalStylesheetModule.java:1199)
at net.sf.saxon.style.Compilation.compilePackage(Compilation.java:262)
at net.sf.saxon.style.StylesheetModule.loadStylesheet(StylesheetModule.java:260)
at net.sf.saxon.style.Compilation.compileSingletonPackage(Compilation.java:101)
at net.sf.saxon.s9api.XsltCompiler.compile(XsltCompiler.java:859)
at net.sf.saxon.Transform.doTransform(Transform.java:727)
at net.sf.saxon.Transform.main(Transform.java:77)
Is that the same problem already fixed or do you need a new bug report?
This latest test case also causes a NullPointerException in Saxon-EE 9.6.0.9J:
java.lang.NullPointerException
at com.saxonica.xslt3.instruct.MergeInstr$MergeSource.copy(MergeInstr.java:91)
at com.saxonica.xslt3.instruct.MergeInstr.copy(MergeInstr.java:702)
at net.sf.saxon.expr.UntypedSequenceConverter.copy(UntypedSequenceConverter.java:162)
at net.sf.saxon.expr.ItemChecker.copy(ItemChecker.java:248)
at net.sf.saxon.expr.parser.ExpressionTool.inlineVariableReferences(ExpressionTool.java:1292)
at net.sf.saxon.expr.parser.ExpressionTool.inlineVariableReferences(ExpressionTool.java:1302)
at net.sf.saxon.expr.parser.ExpressionTool.inlineVariableReferences(ExpressionTool.java:1302)
at net.sf.saxon.expr.Assignation.replaceVariable(Assignation.java:470)
at net.sf.saxon.expr.LetExpression.optimize(LetExpression.java:231)
at net.sf.saxon.expr.parser.ExpressionVisitor.optimize(ExpressionVisitor.java:246)
at net.sf.saxon.style.XSLTemplate.optimize(XSLTemplate.java:624)
at net.sf.saxon.style.StylesheetPackage.optimizeTopLevel(StylesheetPackage.java:1216)
at net.sf.saxon.style.StylesheetPackage.compile(StylesheetPackage.java:1083)
at net.sf.saxon.style.Compilation.compilePackage(Compilation.java:201)
at net.sf.saxon.style.Compilation.compileSingletonPackage(Compilation.java:94)
at net.sf.saxon.s9api.XsltCompiler.compile(XsltCompiler.java:543)
at net.sf.saxon.Transform.doTransform(Transform.java:601)
at net.sf.saxon.Transform.main(Transform.java:80)
Updated by O'Neil Delpratt over 8 years ago
- % Done changed from 0 to 100
- Fixed in Maintenance Release 9.7.0.7 added
Bug fix applied in the Saxon 9.7.0.7 maintenance release.
Updated by O'Neil Delpratt over 8 years ago
- Status changed from Resolved to Closed
Updated by O'Neil Delpratt over 7 years ago
- Applies to branch trunk added
- Applies to branch deleted (
9.8)
Updated by O'Neil Delpratt over 7 years ago
- Fix Committed on Branch trunk added
- Fix Committed on Branch deleted (
9.8)
Please register to edit this issue