Actions
Bug #6159
closed![Author: Johan Gheys](https://www.gravatar.com/avatar/488363e2a5858062d4459679a5d97e66?rating=PG&size=50&default=https%3A%2F%2Fassets.plan.io%2Fimages%2Fdefault_avatar.png)
![Assignee: Michael Kay](https://www.gravatar.com/avatar/db6526d63053f09b62e52c2da8b2230a?rating=PG&size=22&default=https%3A%2F%2Fassets.plan.io%2Fimages%2Fdefault_avatar.png)
sql: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>
Please register to edit this issue
Actions