Project

Profile

Help

Saxon 12 J crashes on fn:transform with base-output-uri:'urn:to-string' with java.lang.NullPointerException while SaxonCS 12 runs the code

Added by Martin Honnen about 1 year ago

Due to shortcomings of the SaxonC Python API to capture serialized result documents I started playing with using XPath and fn:transform instead to run XSLT 3, on experimenting with that I have found an interesting case where SaxonCS 12 runs the code fine while SaxonJ 12 crashes out with a NullPointerException.

So the code calls fn:transform and allows you to set the base-output-uri, I experimented with a non hierarchic one like urn:to-string and SaxonCS swallows that fine while SaxonJ crashes.

Here is the (XQuery) code:

declare namespace map = "http://www.w3.org/2005/xpath-functions/map";
declare namespace array = "http://www.w3.org/2005/xpath-functions/array";

declare namespace output = "http://www.w3.org/2010/xslt-xquery-serialization";

declare option output:method 'json';
declare option output:indent 'yes';

declare variable $base-output-uri as xs:string? external := ();


let $stylesheet-text := ``[<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="3.0" expand-text="yes">
    <xsl:output method="xml" indent="yes"/>
    <xsl:template name="xsl:initial-template">
      <main-template>
          <xsl:for-each select="1 to 3">
            <creating-xml-result>{.}</creating-xml-result>
            <xsl:result-document href="result-{.}.xml" method="xml" indent="yes">
                <xsl:document>
                  <root>
                    <xsl:for-each select="1 to .">
                      <item>{.}</item>
                    </xsl:for-each>
                  </root>
                </xsl:document>
            </xsl:result-document>
            <creating-json-result>{.}</creating-json-result>
            <xsl:result-document href="result-{.}.json" method="json" indent="yes">
                <xsl:sequence
                  select="map { 'name' : 'result ' || ., 'data' : array { 1 to . } }"/>
            </xsl:result-document>
            <xsl:result-document href="result-adaptive{.}.txt" method="adaptive" indent="yes">
                <xsl:sequence
                  select="map { 'name' : 'result ' || ., 'data' : 1 to .  }"/>
            </xsl:result-document>
          </xsl:for-each>
        </main-template>
    </xsl:template>
</xsl:stylesheet>]``
return 
if (empty($base-output-uri))
then
  transform(map{ "stylesheet-text": $stylesheet-text, "delivery-format": "serialized" })
else
  transform(map{ "stylesheet-text": $stylesheet-text, "delivery-format": "serialized", "base-output-uri": trace($base-output-uri) })

Stack trace with Saxon Java 12 HE:

PS C:\Users\marti\OneDrive\Documents\xslt\blog-xslt-3-by-example\fn-transform-output-methods> java -cp 'C:\Program Files\Saxonica\SaxonHE12-0J\saxon-he-12.0.jar' net.sf.saxon.Query .\initial-template-test0.xq base-output-uri=urn:to-string
* [1]: xs:string: urn:to-string
java.lang.NullPointerException
        at net.sf.saxon.functions.TransformFn$SerializedDeliverer.resolve(TransformFn.java:1216)
        at net.sf.saxon.expr.instruct.ResultDocument.makeReceiver(ResultDocument.java:530)
        at net.sf.saxon.expr.instruct.ResultDocument.processLeft(ResultDocument.java:480)
        at net.sf.saxon.expr.instruct.ResultDocument.processInstruction(ResultDocument.java:401)
        at net.sf.saxon.Configuration.processResultDocument(Configuration.java:2336)
        at net.sf.saxon.expr.instruct.ResultDocument$ResultDocumentElaborator.lambda$elaborateForPush$0(ResultDocument.java:977)
        at net.sf.saxon.expr.instruct.Block$BlockElaborator.lambda$elaborateForPush$4(Block.java:898)
        at net.sf.saxon.expr.instruct.ForEach$ForEachElaborator.lambda$elaborateForPush$4(ForEach.java:706)
        at net.sf.saxon.expr.instruct.FixedElement$FixedElementElaborator.lambda$elaborateForPush$0(FixedElement.java:653)
        at net.sf.saxon.expr.instruct.NamedTemplate.expand(NamedTemplate.java:274)
        at net.sf.saxon.trans.XsltController.callTemplate(XsltController.java:872)
        at net.sf.saxon.s9api.Xslt30Transformer.callTemplate(Xslt30Transformer.java:486)
        at net.sf.saxon.functions.TransformFn.call(TransformFn.java:811)
        at net.sf.saxon.expr.SystemFunctionCall$SystemFunctionCallElaborator.lambda$elaborateForPull$1(SystemFunctionCall.java:608)
        at net.sf.saxon.expr.elab.PullElaborator.lambda$elaborateForPush$0(PullElaborator.java:38)
        at net.sf.saxon.expr.instruct.Choose$ChooseExprElaborator.lambda$elaborateForPush$11(Choose.java:1176)
        at net.sf.saxon.query.XQueryExpression.processQuery(XQueryExpression.java:499)
        at net.sf.saxon.query.XQueryExpression.run(XQueryExpression.java:473)
        at net.sf.saxon.s9api.XQueryEvaluator.run(XQueryEvaluator.java:464)
        at net.sf.saxon.Query.runQuery(Query.java:975)
        at net.sf.saxon.Query.doQuery(Query.java:444)
        at net.sf.saxon.Query.main(Query.java:106)
Error in xsl:result-document/@href on line 7 column 82
   Exception thrown by output resolver
java.lang.NullPointerException
        at net.sf.saxon.functions.TransformFn$SerializedDeliverer.resolve(TransformFn.java:1216)
        at net.sf.saxon.expr.instruct.ResultDocument.makeReceiver(ResultDocument.java:530)
        at net.sf.saxon.expr.instruct.ResultDocument.processLeft(ResultDocument.java:480)
        at net.sf.saxon.expr.instruct.ResultDocument.processInstruction(ResultDocument.java:401)
        at net.sf.saxon.Configuration.processResultDocument(Configuration.java:2336)
        at net.sf.saxon.expr.instruct.ResultDocument$ResultDocumentElaborator.lambda$elaborateForPush$0(ResultDocument.java:977)
        at net.sf.saxon.expr.instruct.Block$BlockElaborator.lambda$elaborateForPush$4(Block.java:898)
        at net.sf.saxon.expr.instruct.ForEach$ForEachElaborator.lambda$elaborateForPush$4(ForEach.java:706)
        at net.sf.saxon.expr.instruct.FixedElement$FixedElementElaborator.lambda$elaborateForPush$0(FixedElement.java:653)
        at net.sf.saxon.expr.instruct.NamedTemplate.expand(NamedTemplate.java:274)
        at net.sf.saxon.trans.XsltController.callTemplate(XsltController.java:872)
        at net.sf.saxon.s9api.Xslt30Transformer.callTemplate(Xslt30Transformer.java:486)
        at net.sf.saxon.functions.TransformFn.call(TransformFn.java:811)
        at net.sf.saxon.expr.SystemFunctionCall$SystemFunctionCallElaborator.lambda$elaborateForPull$1(SystemFunctionCall.java:608)
        at net.sf.saxon.expr.elab.PullElaborator.lambda$elaborateForPush$0(PullElaborator.java:38)
        at net.sf.saxon.expr.instruct.Choose$ChooseExprElaborator.lambda$elaborateForPush$11(Choose.java:1176)
        at net.sf.saxon.query.XQueryExpression.processQuery(XQueryExpression.java:499)
        at net.sf.saxon.query.XQueryExpression.run(XQueryExpression.java:473)
        at net.sf.saxon.s9api.XQueryEvaluator.run(XQueryEvaluator.java:464)
        at net.sf.saxon.Query.runQuery(Query.java:975)
        at net.sf.saxon.Query.doQuery(Query.java:444)
        at net.sf.saxon.Query.main(Query.java:106)

at template xsl:initial-template on line 3 column 47
nullQuery failed with dynamic error: Exception thrown by output resolver

Not being able to resolve the relative xsl:result-document hrefs against the base-output-uri urn:to-string might be the right thing but I guess you don't want to crash with a NullPointerException.

But as I said, SaxonCS does manage to run the code:

PS C:\Users\marti\OneDrive\Documents\xslt\blog-xslt-3-by-example\fn-transform-output-methods> & 'C:\Program Files\Saxonica\SaxonCS-12.0\SaxonCS.exe' query .\initial-template-test0.xq base-output-uri=urn:to-string
...
* [1]: xs:string: urn:to-string
{
  "urn:result-1.xml": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<root>\n   <item>1<\/item>\n<\/root>\n",
  "urn:result-2.xml": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<root>\n   <item>1<\/item>\n   <item>2<\/item>\n<\/root>\n",
  "urn:result-3.xml": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<root>\n   <item>1<\/item>\n   <item>2<\/item>\n   <item>3<\/item>\n<\/root>\n",
  "urn:to-string": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<main-template>\n   <creating-xml-result>1<\/creating-xml-result>\n   <creating-json-result>1<\/creating-json-result>\n   <creating-xml-result>2<\/creating-xml-result>\n   <creating-json-result>2<\/creating-json-result>\n   <creating-xml-result>3<\/creating-xml-result>\n   <creating-json-result>3<\/creating-json-result>\n<\/main-template>\n",
  "urn:result-1.json": "{\n  \"data\": [ 1 ],\n  \"name\": \"result 1\"\n}",
  "urn:result-2.json": "{\n  \"data\": [ 1, 2 ],\n  \"name\": \"result 2\"\n}",
  "urn:result-3.json": "{\n  \"data\": [ 1, 2, 3 ],\n  \"name\": \"result 3\"\n}",
  "urn:result-adaptive1.txt": "map{\"data\":1,\"name\":\"result 1\"}",
  "urn:result-adaptive2.txt": "map{\"data\":(1,2),\"name\":\"result 2\"}",
  "urn:result-adaptive3.txt": "map{\"data\":(1,2,3),\"name\":\"result 3\"}"
}

Replies (3)

Please register to reply

RE: Saxon 12 J crashes on fn:transform with base-output-uri:'urn:to-string' with java.lang.NullPointerException while SaxonCS 12 runs the code - Added by Michael Kay about 1 year ago

Indeed, I would expect that supplying a non-hierarchic base URI should lead to a clean error message saying that a relative URI can't be resolved; I wouldn't expect it to lead to an NPE.

RE: Saxon 12 J crashes on fn:transform with base-output-uri:'urn:to-string' with java.lang.NullPointerException while SaxonCS 12 runs the code - Added by Norm Tovey-Walsh about 1 year ago

Indeed, I would expect that supplying a non-hierarchic base URI should lead to a clean
error message saying that a relative URI can't be resolved; I wouldn't expect it to lead
to an NPE.

I did fix an NPE in the resolver just last weekend or thereabouts. Alas,
just after we shipped Saxon 12.

Martin, can you try it against XML Resolver 4.6.4 and see if it is fixed?

Be seeing you,
norm

--
Norm Tovey-Walsh
Saxonica

RE: Saxon 12 J crashes on fn:transform with base-output-uri:'urn:to-string' with java.lang.NullPointerException while SaxonCS 12 runs the code - Added by Martin Honnen about 1 year ago

I tried but it doesn't appear to have changed anything:

PS C:\Users\marti\OneDrive\Documents\xslt\blog-xslt-3-by-example\fn-transform-output-methods> java -cp 'C:\Program Files\Saxonica\SaxonHE12-0J\saxon-he-12.0.jar;C:\Users\marti\Downloads\xmlresolver-4.6.4.jar;C:\Users\marti\Downloads\xmlresolver-4.6.4-data.jar' net.sf.saxon.Query .\initial-template-test0.xq base-output-uri=urn:to-string
* [1]: xs:string: urn:to-string
java.lang.NullPointerException
        at net.sf.saxon.functions.TransformFn$SerializedDeliverer.resolve(TransformFn.java:1216)
        at net.sf.saxon.expr.instruct.ResultDocument.makeReceiver(ResultDocument.java:530)
        at net.sf.saxon.expr.instruct.ResultDocument.processLeft(ResultDocument.java:480)
        at net.sf.saxon.expr.instruct.ResultDocument.processInstruction(ResultDocument.java:401)
        at net.sf.saxon.Configuration.processResultDocument(Configuration.java:2336)
        at net.sf.saxon.expr.instruct.ResultDocument$ResultDocumentElaborator.lambda$elaborateForPush$0(ResultDocument.java:977)
        at net.sf.saxon.expr.instruct.Block$BlockElaborator.lambda$elaborateForPush$4(Block.java:898)
        at net.sf.saxon.expr.instruct.ForEach$ForEachElaborator.lambda$elaborateForPush$4(ForEach.java:706)
        at net.sf.saxon.expr.instruct.FixedElement$FixedElementElaborator.lambda$elaborateForPush$0(FixedElement.java:653)
        at net.sf.saxon.expr.instruct.NamedTemplate.expand(NamedTemplate.java:274)
        at net.sf.saxon.trans.XsltController.callTemplate(XsltController.java:872)
        at net.sf.saxon.s9api.Xslt30Transformer.callTemplate(Xslt30Transformer.java:486)
        at net.sf.saxon.functions.TransformFn.call(TransformFn.java:811)
        at net.sf.saxon.expr.SystemFunctionCall$SystemFunctionCallElaborator.lambda$elaborateForPull$1(SystemFunctionCall.java:608)
        at net.sf.saxon.expr.elab.PullElaborator.lambda$elaborateForPush$0(PullElaborator.java:38)
        at net.sf.saxon.expr.instruct.Choose$ChooseExprElaborator.lambda$elaborateForPush$11(Choose.java:1176)
        at net.sf.saxon.query.XQueryExpression.processQuery(XQueryExpression.java:499)
        at net.sf.saxon.query.XQueryExpression.run(XQueryExpression.java:473)
        at net.sf.saxon.s9api.XQueryEvaluator.run(XQueryEvaluator.java:464)
        at net.sf.saxon.Query.runQuery(Query.java:975)
        at net.sf.saxon.Query.doQuery(Query.java:444)
        at net.sf.saxon.Query.main(Query.java:106)
Error in xsl:result-document/@href on line 7 column 82
   Exception thrown by output resolver
java.lang.NullPointerException
        at net.sf.saxon.functions.TransformFn$SerializedDeliverer.resolve(TransformFn.java:1216)
        at net.sf.saxon.expr.instruct.ResultDocument.makeReceiver(ResultDocument.java:530)
        at net.sf.saxon.expr.instruct.ResultDocument.processLeft(ResultDocument.java:480)
        at net.sf.saxon.expr.instruct.ResultDocument.processInstruction(ResultDocument.java:401)
        at net.sf.saxon.Configuration.processResultDocument(Configuration.java:2336)
        at net.sf.saxon.expr.instruct.ResultDocument$ResultDocumentElaborator.lambda$elaborateForPush$0(ResultDocument.java:977)
        at net.sf.saxon.expr.instruct.Block$BlockElaborator.lambda$elaborateForPush$4(Block.java:898)
        at net.sf.saxon.expr.instruct.ForEach$ForEachElaborator.lambda$elaborateForPush$4(ForEach.java:706)
        at net.sf.saxon.expr.instruct.FixedElement$FixedElementElaborator.lambda$elaborateForPush$0(FixedElement.java:653)
        at net.sf.saxon.expr.instruct.NamedTemplate.expand(NamedTemplate.java:274)
        at net.sf.saxon.trans.XsltController.callTemplate(XsltController.java:872)
        at net.sf.saxon.s9api.Xslt30Transformer.callTemplate(Xslt30Transformer.java:486)
        at net.sf.saxon.functions.TransformFn.call(TransformFn.java:811)
        at net.sf.saxon.expr.SystemFunctionCall$SystemFunctionCallElaborator.lambda$elaborateForPull$1(SystemFunctionCall.java:608)
        at net.sf.saxon.expr.elab.PullElaborator.lambda$elaborateForPush$0(PullElaborator.java:38)
        at net.sf.saxon.expr.instruct.Choose$ChooseExprElaborator.lambda$elaborateForPush$11(Choose.java:1176)
        at net.sf.saxon.query.XQueryExpression.processQuery(XQueryExpression.java:499)
        at net.sf.saxon.query.XQueryExpression.run(XQueryExpression.java:473)
        at net.sf.saxon.s9api.XQueryEvaluator.run(XQueryEvaluator.java:464)
        at net.sf.saxon.Query.runQuery(Query.java:975)
        at net.sf.saxon.Query.doQuery(Query.java:444)
        at net.sf.saxon.Query.main(Query.java:106)

at template xsl:initial-template on line 3 column 47
nullQuery failed with dynamic error: Exception thrown by output resolver
    (1-3/3)

    Please register to reply