DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=22611>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=22611

better error handling when attempting to serialize a null text node

           Summary: better error handling when attempting to serialize a
                    null text node
           Product: XalanJ2
           Version: 2.5
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: Minor
          Priority: Other
         Component: org.apache.xml.utils
        AssignedTo: [EMAIL PROTECTED]
        ReportedBy: [EMAIL PROTECTED]


A minor enhancement:

If I try to serialize a DOM document which contains a text node with null text,
Xalan throws a NullPointerException, which is fine except that the exception
gives me no clue which text node had null text. 

The stack trace (from xalan 2.4 but it is roughly the same with xalan 2.5) is:

Exception Error serialising [EMAIL PROTECTED]: null
java.lang.NullPointerException
        at org.apache.xml.utils.TreeWalker.dispatachChars(TreeWalker.java:259)
        at org.apache.xml.utils.TreeWalker.startNode(TreeWalker.java:403)
        at org.apache.xml.utils.TreeWalker.traverse(TreeWalker.java:167)
        at
org.apache.xalan.transformer.TransformerIdentityImpl.transform(TransformerIdentityImpl.java:325)

The following patch to TreeWalker.java makes the 
exception more verbose, to facilitate debugging:

    private final void dispatachChars(Node node)
       throws org.xml.sax.SAXException
    {
      if(m_contentHandler instanceof
org.apache.xml.dtm.ref.dom2dtm.DOM2DTM.CharacterNodeHandler)
      {
       
((org.apache.xml.dtm.ref.dom2dtm.DOM2DTM.CharacterNodeHandler)m_contentHandler).characters(node);
      }
      else
      {
        String data = ((Text) node).getData();
+       if ( data == null )
+          throw new NullPointerException( "node " + node.getClass().getName() +
+            ": " + node.getNodeName() + ": " + node.getLocalName() +
+             " with parent " + node.getParentNode() + " has null text" );
        this.m_contentHandler.characters(data.toCharArray(), 0, data.length());
      }
    }

Reply via email to