Actions
Bug #6159
closedsql:query() throws NullPointerException when retrieving a column with null value
Start date:
2023-08-06
Due date:
% Done:
100%
Estimated time:
Legacy ID:
Applies to branch:
11, 12, trunk
Fix Committed on Branch:
11, 12, trunk
Description
When retrieving data from a table having a column with null value with the following code
<xsl:template name="xsl:initial-template" match="/">
<xsl:variable name="row" select="sql:query($connection, $table, '*', $condition)"/>
<xsl:sequence select="shared:log('DEBUG', concat('Nb of rows = ', count($row)))"/>
<xsl:variable name="output-uri" select="shared:path-to-uri($output-file)"/>
<xsl:sequence select="shared:log('DEBUG', concat('Exporting ', $output-uri))"/>
<xsl:result-document href="{$output-uri}" method="xml">
<xsl:element name="{$table-synonym}s">
<xsl:for-each select="$row">
<xsl:variable name="row-map" select="."/>
<xsl:element name="{$table-synonym}">
<xsl:for-each select="map:keys($row-map)">
<xsl:attribute name="{lower-case(.)}" select="map:get($row-map, .)"/>
</xsl:for-each>
</xsl:element>
</xsl:for-each>
</xsl:element>
</xsl:result-document>
</xsl:template>
we get the following error message:
java.lang.NullPointerException
at java.util.Objects.requireNonNull(Objects.java:203)
at net.sf.saxon.str.StringView.<init>(StringView.java:26)
at net.sf.saxon.str.StringView.of(StringView.java:31)
at net.sf.saxon.value.StringValue.<init>(StringValue.java:106)
at net.sf.saxon.value.StringValue.<init>(StringValue.java:91)
at com.saxonica.functions.sql.SQLFunctionSet.sqlQueryResult(SQLFunctionSet.java:64)
at com.saxonica.functions.sql.SQLQueryFn.call(SQLQueryFn.java:84)
at net.sf.saxon.expr.SystemFunctionCall$SystemFunctionCallElaborator.lambda$elaborateForPull$3(SystemFunctionCall.java:625)
at net.sf.saxon.expr.elab.EagerPullEvaluator.evaluate(EagerPullEvaluator.java:37)
at net.sf.saxon.expr.LetExpression$LetExprElaborator.lambda$setAllVariables$0(LetExpression.java:839)
at net.sf.saxon.expr.LetExpression$LetExprElaborator.lambda$elaborateForPush$6(LetExpression.java:940)
at net.sf.saxon.expr.instruct.TemplateRule.applyLeavingTail(TemplateRule.java:393)
at net.sf.saxon.trans.Mode.handleRuleNotNull(Mode.java:587)
at net.sf.saxon.trans.Mode.applyTemplates(Mode.java:521)
at net.sf.saxon.trans.XsltController.applyTemplates(XsltController.java:684)
at com.saxonica.functions.extfn.TransformFn.call(TransformFn.java:103)
at net.sf.saxon.expr.SystemFunctionCall$SystemFunctionCallElaborator.lambda$elaborateForPull$3(SystemFunctionCall.java:625)
at net.sf.saxon.expr.elab.LazyPullEvaluator.evaluate(LazyPullEvaluator.java:39)
at net.sf.saxon.expr.SystemFunctionCall$SystemFunctionCallElaborator.lambda$elaborateForPull$2(SystemFunctionCall.java:615)
at net.sf.saxon.expr.elab.LazyPullEvaluator.evaluate(LazyPullEvaluator.java:39)
at net.sf.saxon.expr.SystemFunctionCall$SystemFunctionCallElaborator.lambda$elaborateForPull$2(SystemFunctionCall.java:616)
at net.sf.saxon.expr.LetExpression$LetExprElaborator.lambda$elaborateForPull$5(LetExpression.java:927)
at net.sf.saxon.expr.instruct.Block$BlockElaborator$BlockIterator.getNthChildIterator(Block.java:832)
at net.sf.saxon.expr.instruct.AbstractBlockIterator.next(AbstractBlockIterator.java:66)
at net.sf.saxon.value.SingletonClosure.asItem(SingletonClosure.java:111)
at net.sf.saxon.value.SingletonClosure.iterate(SingletonClosure.java:71)
at net.sf.saxon.expr.UserFunctionCall$UserFunctionCallElaborator.lambda$elaborateForPull$0(UserFunctionCall.java:746)
at net.sf.saxon.value.SingletonClosure.asItem(SingletonClosure.java:111)
at net.sf.saxon.value.SingletonClosure.materialize(SingletonClosure.java:162)
at net.sf.saxon.expr.elab.LocalVariableEvaluator.evaluate(LocalVariableEvaluator.java:31)
at net.sf.saxon.expr.SystemFunctionCall$SystemFunctionCallElaborator.lambda$elaborateForPull$1(SystemFunctionCall.java:605)
at net.sf.saxon.expr.sort.SortExpression$SortExprElaborator.lambda$elaborateForPull$0(SortExpression.java:511)
at net.sf.saxon.expr.instruct.ForEach$ForEachElaborator.lambda$elaborateForPush$5(ForEach.java:737)
at net.sf.saxon.expr.instruct.Block$BlockElaborator.lambda$elaborateForPush$1(Block.java:853)
at net.sf.saxon.expr.instruct.NamedTemplate.expand(NamedTemplate.java:269)
at net.sf.saxon.expr.instruct.CallTemplate$CallTemplateElaborator.lambda$elaborateForPush$1(CallTemplate.java:633)
at net.sf.saxon.expr.instruct.Block$BlockElaborator.lambda$elaborateForPush$2(Block.java:864)
at net.sf.saxon.expr.LetExpression$LetExprElaborator.lambda$elaborateForPush$6(LetExpression.java:942)
at net.sf.saxon.expr.instruct.Block$BlockElaborator.lambda$elaborateForPush$1(Block.java:853)
at net.sf.saxon.expr.LetExpression$LetExprElaborator.lambda$elaborateForPush$6(LetExpression.java:942)
at net.sf.saxon.expr.instruct.NamedTemplate.expand(NamedTemplate.java:269)
at net.sf.saxon.expr.instruct.CallTemplate$CallTemplateElaborator.lambda$elaborateForPush$1(CallTemplate.java:633)
at net.sf.saxon.expr.LetExpression$LetExprElaborator.lambda$elaborateForPush$6(LetExpression.java:942)
at net.sf.saxon.expr.instruct.ForEach$ForEachElaborator.lambda$elaborateForPush$5(ForEach.java:741)
at net.sf.saxon.expr.LetExpression$LetExprElaborator.lambda$elaborateForPush$6(LetExpression.java:942)
at net.sf.saxon.expr.instruct.NamedTemplate.expand(NamedTemplate.java:269)
at net.sf.saxon.expr.instruct.CallTemplate$CallTemplateElaborator.lambda$elaborateForPush$1(CallTemplate.java:633)
at net.sf.saxon.expr.instruct.Block$BlockElaborator.lambda$elaborateForPush$4(Block.java:895)
at net.sf.saxon.expr.LetExpression$LetExprElaborator.lambda$elaborateForPush$6(LetExpression.java:942)
at net.sf.saxon.expr.TryCatch$TryCatchElaborator.lambda$elaborateForPush$1(TryCatch.java:340)
at net.sf.saxon.expr.instruct.NamedTemplate.expand(NamedTemplate.java:269)
at net.sf.saxon.trans.XsltController.callTemplate(XsltController.java:872)
at net.sf.saxon.s9api.Xslt30Transformer.callTemplate(Xslt30Transformer.java:503)
at net.sf.saxon.Transform.processFile(Transform.java:1375)
at net.sf.saxon.Transform.doTransform(Transform.java:879)
at net.sf.saxon.Transform.main(Transform.java:83)
Retrieving data with the instruction sql:query works fine:
<xsl:template name="xsl:initial-template" match="/">
<xsl:variable name="row" as="element()*">
<sql:query connection="$connection" table="{$table}" where="{$condition}" column="*"/>
</xsl:variable>
<xsl:sequence select="shared:log('DEBUG', concat('Nb of rows = ', count($row)))"/>
<xsl:variable name="output-uri" select="shared:path-to-uri($output-file)"/>
<xsl:sequence select="shared:log('DEBUG', concat('Exporting ', $output-uri))"/>
<xsl:result-document href="{$output-uri}" method="xml">
<xsl:element name="{$table-synonym}s">
<xsl:for-each select="$row">
<xsl:element name="{$table-synonym}">
<xsl:for-each select="*">
<xsl:attribute name="{lower-case(local-name(.))}" select="."/>
</xsl:for-each>
</xsl:element>
</xsl:for-each>
</xsl:element>
</xsl:result-document>
</xsl:template>
Updated by Michael Kay over 1 year ago
- Status changed from New to Resolved
- Assignee set to Michael Kay
- Applies to branch 11, 12, trunk added
- Fix Committed on Branch 11, 12, trunk added
- Platforms Java added
Fixed (but without specific testing).
Updated by Johan Gheys over 1 year ago
Thanks, with this fix we will be able to replace the sql instructions with sql functions everywhere in our xslt's.
Updated by Debbie Lockett over 1 year ago
- % Done changed from 0 to 50
- Fixed in Maintenance Release 11.6 added
Bug fix applied in the Saxon 11.6 maintenance release.
Updated by O'Neil Delpratt about 1 year ago
- Status changed from Resolved to Closed
- % Done changed from 50 to 100
- Fixed in Maintenance Release 12.4 added
Bug fix applied in the Saxon 12.4 Maintenance release
Please register to edit this issue
Actions