Saxonica / Saxon-CE

XSLT 2.0 in the browser
117 stars 31 forks source link

Behavior when uri has null value #13

Open acarolgon opened 1 year ago

acarolgon commented 1 year ago

When using saxon I had some problems with nullPointer

java.lang.NullPointerException: null
    at net.sf.saxon.event.ReceivingContentHandler.getNodeName(ReceivingContentHandler.java:529) ~[Saxon-HE-11.4.jar:?]
    at net.sf.saxon.event.ReceivingContentHandler.startElement(ReceivingContentHandler.java:375) ~[Saxon-HE-11.4.jar:?]

Shouldn't the null value have the same behavior as empty string?

michaelhkay commented 1 year ago

You've raised the question in a rather strange place - the place for Saxon questions is the forum at saxonica.plan.io. This GitHub repository relates to the obsolete product Saxon-CE, which was a predecessor to SaxonJS.

The Java method ReceivingContentHandler.startElement() implements the interface org.xml.sax.ContentHandler.startElement(), and there's nothing in the Javadoc for that interface that suggests any of the arguments can be null. In fact, it clearly indicates that absent values are represented as a zero-length string.

There are some complications with this interface, because it's designed as a callback for XML parsers, and the way the arguments are supplied is supposed to depend on how the XML parser is configured. But we don't necessarily know how the XML parser was configured (and the caller might not even be an XML parser), so we have to make assumptions. It's also a very performance-critical interface so we can't afford to validate everything passed across. But despite the fact that the interface spec allows lots of variations in what's passed across, none of those variations suggest that null values should be accepted.