Title: Help - NullPointerException with DocumentSource
Hi Kesav
 
You're exception is caused by a null String being added to your dom4j document. When its written out to TrAX (JAXP) for XSLT its causing the exception. More comments below...

----- Original Message -----
Sent: Thursday, September 13, 2001 1:02 AM
Subject: [dom4j-user] Help - NullPointerException with DocumentSource

Hi,

I am using dom4j-1.0 version.  I am trying to apply xsl template to the dom4j Document. 

I am getting the following error
java.lang.NullPointerException
        at org.dom4j.io.SAXWriter.write(SAXWriter.java:149)
        at org.dom4j.io.SAXWriter.writeContent(SAXWriter.java:410)
        at org.dom4j.io.SAXWriter.write(SAXWriter.java:505)
        at org.dom4j.io.SAXWriter.writeContent(SAXWriter.java:405)
        at org.dom4j.io.SAXWriter.write(SAXWriter.java:505)
        at org.dom4j.io.SAXWriter.writeContent(SAXWriter.java:405)
        at org.dom4j.io.SAXWriter.write(SAXWriter.java:505)
        at org.dom4j.io.SAXWriter.writeContent(SAXWriter.java:405)
        at org.dom4j.io.SAXWriter.write(SAXWriter.java:505)
        at org.dom4j.io.SAXWriter.writeContent(SAXWriter.java:405)
        at org.dom4j.io.SAXWriter.write(SAXWriter.java:505)
        at org.dom4j.io.SAXWriter.writeContent(SAXWriter.java:405)
        at org.dom4j.io.SAXWriter.write(SAXWriter.java:127)
        at org.dom4j.io.SAXWriter.parse(SAXWriter.java:387)
        at org.apache.xalan.transformer.TransformerImpl.transform(Unknown Source)
        at org.apache.xalan.transformer.TransformerImpl.transform(Unknown Source)
        at __jspPage1_login_jsp._jspService(__jspPage1_login_jsp.java:51)
        at com.orionserver.http.OrionHttpJspPage.service(Unknown Source)
        at com.evermind._ah._rad(Unknown Source)
        at com.evermind.server.http.JSPServlet.service(Unknown Source)
        at com.evermind._cxb._abe(Unknown Source)
        at com.evermind._cxb._uec(Unknown Source)
        at com.evermind._io._twc(Unknown Source)
        at com.evermind._io._gc(Unknown Source)
        at com.evermind._if.run(Unknown Source)

I saw in the mailing list that this NullPointer bug has been fixed.  My code is like the following, I am using this inside a JSP.

        Transformer transformer = TemplateCache.getTemplate("ItemsXsl");
        Document doc = new InterfaceGenerator().generate(2, false);
        transformer.transform(new DocumentSource(doc), new StreamResult(out));

For the trasform I am getting the NullPointer exception.  My document is a proper document if I write to a file using XMLWriter it writes properly to a file.

 

I made sure XMLWriter would gracefully handle null Strings being in a dom4j document. I've just patched the SAXWriter to be the same, that this exception will no longer happen.

 

When I tried to run from sample console java program the same xml and xsl works properly. 

 

I don't quite understand why it would run from the command line - unless its the behaviour of your InterfaceGenerator code?

James

Reply via email to