How to represent an empty Source

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

How to represent an empty Source

Rademacher, Gunther
According to JAXP Javadoc (for Transformer.transform), an empty source is represented as an empty document as constructed by DocumentBuilder.newDocument.
 
While this suggests creating a DOMSource on a thus constructed node, DOMSource Javadoc tells us that "the Transformer" would do that implicitly when the zero-argument DOMSource constructor has been used. Similarly, StreamSource Javadoc suggests that it might be possible using its zero-argument constructor out of the box, though I have doubts about the explanation of an empty InputStream being used internally.
 
In fact the JRE built-in Xalan indeed supports all of the variants mentioned above, returning a count of 1 for either:
 
 
    StreamSource xsltSource = new StreamSource(new StringReader(
        "<xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform' version='1.0'>\n"
      + "  <xsl:template match='/'>\n"
      + "    <xsl:value-of select='count(descendant-or-self::node())'/>\n"
      + "  </xsl:template>\n"
      + "</xsl:stylesheet>"));
    Transformer transformer =
        TransformerFactory.newInstance().newTransformer(xsltSource);
    for (Source source : new Source[]{
        new DOMSource(db.newDocument()),
        new DOMSource(),
        new StreamSource(),
      }) {
      transformer.transform(source, result);
    }
 
 
Saxon supports the DOMSource variants, but throws a NPE for the StreamSource. But when creating the transformer with a zero-argument newTransformer call, the plain DOMSource variant will also throw:
 
 
    Exception in thread "main" java.lang.NullPointerException: startNode
      at net.sf.saxon.dom.DOMSender.<init>(DOMSender.java:53)
      at net.sf.saxon.dom.DOMObjectModel.sendSource(DOMObjectModel.java:243)
      at net.sf.saxon.event.Sender.send(Sender.java:222)
      at net.sf.saxon.jaxp.IdentityTransformer.transform(IdentityTransformer.java:363)
 
 
This came up in application scenario where at times we have to deal with empty input. Of course it is possibly to work around it, but I wasn't sure where this should possibly be considered a bug.
 
Thanks,
Gunther
 

Software AG – Sitz/Registered office: Uhlandstraße 12, 64297 Darmstadt, Germany – Registergericht/Commercial register: Darmstadt HRB 1562 - Vorstand/Management Board: Karl-Heinz Streibich (Vorsitzender/Chairman), Eric Duffaut, Dr. Wolfram Jost, Arnd Zinnhardt; - Aufsichtsratsvorsitzender/Chairman of the Supervisory Board: Dr. Andreas Bereczky - http://www.softwareag.com

------------------------------------------------------------------------------
Dive into the World of Parallel Programming! The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help 
Reply | Threaded
Open this post in threaded view
|

Re: How to represent an empty Source

Michael Kay
This bug is relevant:


but it looks as if you have identified additional cases where we need to make similar changes.

The spec for "new StreamSource()" says it creates an input stream "using new InputStream()". But InputStream() is abstract, so that doesn't make much sense. And if it created an "empty source InputStream" in the sense of a stream containing zero bytes, then that would give an XML parsing error. So i think you're asking me to blindly copy what Xalan does when the spec is incoherent.

For the identity transformer, I accept that we should change it so new DOMSource() represents an empty document. But an identity transformation of an empty document doesn't feel like a very interesting use case...


Michael Kay
Saxonica
+44 (0) 118 946 5893




On 7 Jan 2015, at 13:00, Rademacher, Gunther <[hidden email]> wrote:

According to JAXP Javadoc (for Transformer.transform), an empty source is represented as an empty document as constructed by DocumentBuilder.newDocument.
 
While this suggests creating a DOMSource on a thus constructed node, DOMSource Javadoc tells us that "the Transformer" would do that implicitly when the zero-argument DOMSource constructor has been used. Similarly, StreamSource Javadoc suggests that it might be possible using its zero-argument constructor out of the box, though I have doubts about the explanation of an empty InputStream being used internally.
 
In fact the JRE built-in Xalan indeed supports all of the variants mentioned above, returning a count of 1 for either:
 
 
    StreamSource xsltSource = new StreamSource(new StringReader(
        "<xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform' version='1.0'>\n"
      + "  <xsl:template match='/'>\n"
      + "    <xsl:value-of select='count(descendant-or-self::node())'/>\n"
      + "  </xsl:template>\n"
      + "</xsl:stylesheet>"));
    Transformer transformer =
        TransformerFactory.newInstance().newTransformer(xsltSource);
    for (Source source : new Source[]{
        new DOMSource(db.newDocument()),
        new DOMSource(),
        new StreamSource(),
      }) {
      transformer.transform(source, result);
    }
 
 
Saxon supports the DOMSource variants, but throws a NPE for the StreamSource. But when creating the transformer with a zero-argument newTransformer call, the plain DOMSource variant will also throw:
 
 
    Exception in thread "main" java.lang.NullPointerException: startNode
      at net.sf.saxon.dom.DOMSender.<init>(DOMSender.java:53)
      at net.sf.saxon.dom.DOMObjectModel.sendSource(DOMObjectModel.java:243)
      at net.sf.saxon.event.Sender.send(Sender.java:222)
      at net.sf.saxon.jaxp.IdentityTransformer.transform(IdentityTransformer.java:363)
 
 
This came up in application scenario where at times we have to deal with empty input. Of course it is possibly to work around it, but I wasn't sure where this should possibly be considered a bug.
 
Thanks,
Gunther
 

Software AG – Sitz/Registered office: Uhlandstraße 12, 64297 Darmstadt, Germany – Registergericht/Commercial register: Darmstadt HRB 1562 - Vorstand/Management Board: Karl-Heinz Streibich (Vorsitzender/Chairman), Eric Duffaut, Dr. Wolfram Jost, Arnd Zinnhardt; - Aufsichtsratsvorsitzender/Chairman of the Supervisory Board: Dr. Andreas Bereczky - http://www.softwareag.com
------------------------------------------------------------------------------
Dive into the World of Parallel Programming! The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help


------------------------------------------------------------------------------
New Year. New Location. New Benefits. New Data Center in Ashburn, VA.
GigeNET is offering a free month of service with a new server in Ashburn.
Choose from 2 high performing configs, both with 100TB of bandwidth.
Higher redundancy.Lower latency.Increased capacity.Completely compliant.
www.gigenet.com
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help 
Reply | Threaded
Open this post in threaded view
|

Re: How to represent an empty Source

Rademacher, Gunther

Thanks for looking into this.

 

Admittedly I came across the StreamSource behaviour only when playing around, after getting aware of the DOMSource issue.

 

The null-node DOMSource was supplied to a method accepting a Source formal parameter and running some XQuery on it using s9api.

 

The identity transformation apparently was an over-simplification of the actual observation, which I did while I was exploring whether this kind of DOMSource would be supported at all.

 

In the actual application context, this call-stack was observed:

 

    Caused by: java.lang.NullPointerException

      at net.sf.saxon.dom.DOMObjectModel.unravel(DOMObjectModel.java:303)

      at net.sf.saxon.Configuration.unravel(Configuration.java:3183)

      at net.sf.saxon.Controller.prepareInputTree(Controller.java:1941)

      at net.sf.saxon.functions.DocumentFn.makeDoc(DocumentFn.java:409)

      at EE_main_281410810983.iterate(*module with no systemId*:2)

      at com.saxonica.ee.bytecode.CompiledExpression.iterate(CompiledExpression.java:181)

      at net.sf.saxon.query.XQueryExpression.iterator(XQueryExpression.java:332)

      at net.sf.saxon.s9api.XQueryEvaluator.iterator(XQueryEvaluator.java:478)

 

As it shows some entries from byte-code generation, I also tried without that. Then the top four and bottom two stack entries were the very same as shown above, with the byte-code part being replaced by

 

      at net.sf.saxon.functions.Doc.doc(Doc.java:242)

      at net.sf.saxon.functions.Doc.evaluateItem(Doc.java:192)

      at net.sf.saxon.functions.Doc.evaluateItem(Doc.java:30)

      at net.sf.saxon.expr.Expression.iterate(Expression.java:457)

      at net.sf.saxon.expr.SlashExpression.iterate(SlashExpression.java:848)

      at net.sf.saxon.expr.ForExpression.iterate(ForExpression.java:456)

 

Meanwhile we have added this to the participating URIResolver for avoiding the failure

 

      if (! (source instanceof DOMSource) || ((DOMSource) source).getNode() != null) {

        return source;

      }

      else {

        DocumentImpl document = new DocumentImpl();

        document.setConfiguration(xqueryEvaluator.getUnderlyingQueryContext().getConfiguration());

        return document;

      }

 

and are happy to live with it. Though of course appreciating a fix that would make the null-node DOMSource work.

 

Thanks again,

Gunther

 

From: Michael Kay [mailto:[hidden email]]
Sent: 12 January 2015 17:25
To: Mailing list for the SAXON XSLT and XQuery processor
Subject: Re: [saxon] How to represent an empty Source

 

This bug is relevant:

 

 

but it looks as if you have identified additional cases where we need to make similar changes.

 

The spec for "new StreamSource()" says it creates an input stream "using new InputStream()". But InputStream() is abstract, so that doesn't make much sense. And if it created an "empty source InputStream" in the sense of a stream containing zero bytes, then that would give an XML parsing error. So i think you're asking me to blindly copy what Xalan does when the spec is incoherent.

 

For the identity transformer, I accept that we should change it so new DOMSource() represents an empty document. But an identity transformation of an empty document doesn't feel like a very interesting use case...

 

 

Michael Kay

Saxonica

+44 (0) 118 946 5893

 

 

 

On 7 Jan 2015, at 13:00, Rademacher, Gunther <[hidden email]> wrote:



According to JAXP Javadoc (for Transformer.transform), an empty source is represented as an empty document as constructed by DocumentBuilder.newDocument.

 

While this suggests creating a DOMSource on a thus constructed node, DOMSource Javadoc tells us that "the Transformer" would do that implicitly when the zero-argument DOMSource constructor has been used. Similarly, StreamSource Javadoc suggests that it might be possible using its zero-argument constructor out of the box, though I have doubts about the explanation of an empty InputStream being used internally.

 

In fact the JRE built-in Xalan indeed supports all of the variants mentioned above, returning a count of 1 for either:

 

 

    StreamSource xsltSource = new StreamSource(new StringReader(

        "<xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform' version='1.0'>\n"

      + "  <xsl:template match='/'>\n"

      + "    <xsl:value-of select='count(descendant-or-self::node())'/>\n"

      + "  </xsl:template>\n"

      + "</xsl:stylesheet>"));

    Transformer transformer =

        TransformerFactory.newInstance().newTransformer(xsltSource);

    for (Source source : new Source[]{

        new DOMSource(db.newDocument()),

        new DOMSource(),

        new StreamSource(),

      }) {

      transformer.transform(source, result);

    }

 

 

Saxon supports the DOMSource variants, but throws a NPE for the StreamSource. But when creating the transformer with a zero-argument newTransformer call, the plain DOMSource variant will also throw:

 

 

    Exception in thread "main" java.lang.NullPointerException: startNode

      at net.sf.saxon.dom.DOMSender.<init>(DOMSender.java:53)

      at net.sf.saxon.dom.DOMObjectModel.sendSource(DOMObjectModel.java:243)

      at net.sf.saxon.event.Sender.send(Sender.java:222)

      at net.sf.saxon.jaxp.IdentityTransformer.transform(IdentityTransformer.java:363)

 

 

This came up in application scenario where at times we have to deal with empty input. Of course it is possibly to work around it, but I wasn't sure where this should possibly be considered a bug.

 

Thanks,

Gunther

 

 

Software AG – Sitz/Registered office: Uhlandstraße 12, 64297 Darmstadt, Germany – Registergericht/Commercial register: Darmstadt HRB 1562 - Vorstand/Management Board: Karl-Heinz Streibich (Vorsitzender/Chairman), Eric Duffaut, Dr. Wolfram Jost, Arnd Zinnhardt; - Aufsichtsratsvorsitzender/Chairman of the Supervisory Board: Dr. Andreas Bereczky - http://www.softwareag.com

------------------------------------------------------------------------------
Dive into the World of Parallel Programming! The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help

 


------------------------------------------------------------------------------
New Year. New Location. New Benefits. New Data Center in Ashburn, VA.
GigeNET is offering a free month of service with a new server in Ashburn.
Choose from 2 high performing configs, both with 100TB of bandwidth.
Higher redundancy.Lower latency.Increased capacity.Completely compliant.
http://p.sf.net/sfu/gigenet
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help