You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xalan.apache.org by Tim Cronin <ti...@13-colonies.com> on 2003/01/29 20:43:00 UTC
transforming dom with a CDATA section set to null
I'm using Xalan 2.4.1 and xerces 2.2.1.
(I posted to xerces as well...)
I was building a Document and a passed a null to the call createCDATASection
(this did not fail which surprised me..)
when I tried to transform (basically creating a string of the dom)
public static String toString(Node node)
{
StringWriter sw = new StringWriter();
try
{
Transformer serializer =
TransformerFactory.newInstance().newTransformer();
serializer.transform(new DOMSource(node), new StreamResult(sw));
}
catch (TransformerException e)
{
DOMException de = new DOMException(DOMException.SYNTAX_ERR, "failed to
translate DOM");
de.initCause(e);
throw de;
}
return sw.toString();
}
it I got the following
java.lang.NullPointerException
at
org.apache.xml.utils.TreeWalker.dispatachChars(TreeWalker.java:292)
at org.apache.xml.utils.TreeWalker.startNode(TreeWalker.java:412)
at org.apache.xml.utils.TreeWalker.traverse(TreeWalker.java:191)
at
org.apache.xalan.transformer.TransformerIdentityImpl.transform(TransformerId
entityImpl.java:325)
it also failed for xslt transformation
java.lang.NullPointerException
at
org.apache.xalan.xsltc.runtime.output.StreamXMLOutput.characters(StreamXMLOu
tput.java:199)
at
org.apache.xalan.xsltc.runtime.output.StreamUnknownOutput.characters(StreamU
nknownOutput.java:177)
at org.apache.xalan.xsltc.trax.DOM2TO.parse(DOM2TO.java:144)
at org.apache.xalan.xsltc.trax.DOM2TO.parse(DOM2TO.java:209)
at org.apache.xalan.xsltc.trax.DOM2TO.parse(DOM2TO.java:209)
at org.apache.xalan.xsltc.trax.DOM2TO.parse(DOM2TO.java:115)
at
org.apache.xalan.xsltc.trax.TransformerImpl.transformIdentity(TransformerImp
l.java:612)
at
org.apache.xalan.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:6
32)
I would expect to get a NullPointerException when I created the
CDATASection.
Re: transforming dom with a CDATA section set to null
Posted by Joseph Kesselman <ke...@us.ibm.com>.
I'm afraid this is a clear case of "If it hurts when you do that, and you
know you shouldn't do that, stop doing that."
Passing nulls into the DOM API where they aren't expected may trigger
error responses at the time you set those values or at the time you read
them or both. This was deliberately left for DOM implementations to decide
since it's a performance-versus-robustness issue. Obviously, if the DOM
decided not to spend time protecting itself and instead fails when
accessed, a bad DOM may disrupt the transformation.
We might be able to configure Xalan to check for this. But again, that
means spending cycles testing for something that you shouldn't have
created in the first place.
To resolve this: Determine whether the DOM officially considers null a
legitimate value when set, and if so what it returns when retrieved. If
the answer to the first is yes and the answer to the second is null, Xalan
will have to tolerate the null. If the answer to the first is yes and the
answer to the second is empty-string, Xerces has a problem. If the answer
to the first is null, your application code has a problem.
______________________________________
Joe Kesselman / IBM Research