[ http://issues.apache.org/jira/browse/XALANJ-2265?page=comments#action_12373173 ]
Henry Zongaro commented on XALANJ-2265: --------------------------------------- I believe that null is used as an exceptional value in DOM, and is not intended to be interchangeable with the empty string (except for those bindings where the two are not distinguishable). See the definition of DOMException[1] which states, as an example, that "implementations should raise an implementation-dependent exception if a null argument is passed when null was not expected." The definition of Document.createTextNode[2] does not explicitly permit its argument to be null, so my reading is that it is an incorrect usage of the method. [1] http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core.html#ID-17189187 [2] http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core.html#ID-1975348127 > Creating in-memory DocumentFragment with imbedded null text elements causes > Trax NPE > ------------------------------------------------------------------------------------ > > Key: XALANJ-2265 > URL: http://issues.apache.org/jira/browse/XALANJ-2265 > Project: XalanJ2 > Type: Bug > Components: XSLTC > Versions: 2.7 > Environment: cygwin under XP, java 1.4.2_09 > Reporter: Travis Winfrey > > The trax library cannot handle the null text element, when a DocumentFragment > is created that has some null text nodes. In contrast, other XSLTC libraries > treat the middleName=null variation shown below as <MiddleName/> > Example code to create DocumentFragment with null text element > import org.w3c.dom.Document; > import org.w3c.dom.DocumentFragment; > import org.w3c.dom.Element; > public DocumentFragment createDocFragment(Document doc) throws > ParserConfigurationException, NullPointerException { > DocumentFragment docFrag = doc.createDocumentFragment(); > Element person = doc.createElement("Person"); > String firstName = "George"; > String middleName = ""; > String lastName = "Washington"; > if (this.isMiddleNameNull) { > middleName = null; > } > > person.appendChild(doc.createElement("FirstName")).appendChild(doc.createTextNode(firstName)); > > person.appendChild(doc.createElement("MiddleName")).appendChild(doc.createTextNode(middleName)); > > person.appendChild(doc.createElement("LastName")).appendChild(doc.createTextNode(lastName)); > docFrag.appendChild(person); > return docFrag; > } > Sample xsl code to tickle bug. any of these will work . > <xsl:value-of select="/Person/MiddleName" /> > <xsl:value-of select="." /> > <xsl:value-of select="./*" /> > One cause of the NPE is org.apache.xalan.xsltc.trax.DOM2SAX.parse routine > looks like this: > private void parse(Node node) throws IOException, SAXException { > // .. tlw omit 5 lines ... > switch (node.getNodeType()) { > // ... tlw omit 131 lines ... > case Node.TEXT_NODE: > final String data = node.getNodeValue(); > > _sax.characters(data.toCharArray(), 0, data.length()); // tlw: > kaboom > break; > } > } > This is $Id: DOM2SAX.java,v 1.21 2004/02/16 22:57:21 minchau Exp $ -- This message is automatically generated by JIRA. - If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa - For more information on JIRA, see: http://www.atlassian.com/software/jira --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
