[ http://issues.apache.org/jira/browse/XALANJ-1868?page=all ]
Brian Minchau updated XALANJ-1868:
----------------------------------
Version: Latest Development Code
(was: 2.5)
> NullPointerException in TreeWalker
> ----------------------------------
>
> Key: XALANJ-1868
> URL: http://issues.apache.org/jira/browse/XALANJ-1868
> Project: XalanJ2
> Type: Bug
> Components: Other
> Versions: Latest Development Code
> Environment: Operating System: All
> Platform: All
> Reporter: Joaquin Diez
> Assignee: Xalan Developers Mailing List
> Attachments: TestTransformerFactory.java
>
> This is the code That produces de error.
> package org.yokin.test;
> import java.io.FileReader;
> import java.io.StringWriter;
> import javax.xml.parsers.DocumentBuilder;
> import javax.xml.parsers.DocumentBuilderFactory;
> import javax.xml.transform.OutputKeys;
> import javax.xml.transform.Transformer;
> import javax.xml.transform.TransformerFactory;
> import javax.xml.transform.dom.DOMSource;
> import javax.xml.transform.stream.StreamResult;
> import org.w3c.dom.Document;
> import org.w3c.dom.Node;
> import org.xml.sax.InputSource;
> public class TestTransformerFactory {
> public static void main(String[] args) {
>
> TestTransformerFactory obj = new TestTransformerFactory();
>
>
> Node nodo = null;
> Node texto = null;
> Node rootNode = null;
> Document doc = getDocumentBuilder().newDocument();
>
> rootNode = doc.createElement("ROOT");
> doc.appendChild(rootNode);
>
> nodo = doc.createElement("HOLA");
> texto = doc.createTextNode("saludos");
> nodo.appendChild(texto);
>
> rootNode.appendChild(nodo);
>
>
> nodo = doc.createElement("HOLA2");
> texto = doc.createTextNode(null);
> nodo.appendChild(texto);
>
> rootNode.appendChild(nodo);
>
>
> obj.toString(doc);
> }
>
>
> private void toString(Document doc){
>
> try{
> StringWriter stringOut = new StringWriter();
> TransformerFactory trasnFactory =
> TransformerFactory.newInstance();
>
> Transformer transformer = trasnFactory.newTransformer();
>
> transformer.setOutputProperty(OutputKeys.ENCODING,
> "ISO-8859-1");
>
> DOMSource source = new DOMSource(doc);
>
> StreamResult streamResult = new StreamResult(stringOut);
>
> transformer.transform(source, streamResult);
>
> System.out.println(stringOut.getBuffer().toString());
>
> }catch(Exception e){
> e.printStackTrace();
> System.out.println(e);
> }
>
> }
>
>
> public static Document getXMLFile(String xmlFile) {
> Document objDoc = null;
> try {
>
> FileReader fileRead = new FileReader(xmlFile);
> InputSource inputsource = new InputSource(fileRead);
>
> objDoc = getDocumentBuilder().parse(inputsource);
> } catch (Throwable theException) {
> theException.printStackTrace();
> System.out.println("File Exception : " +
> theException.getMessage());
> }
> return objDoc;
> }
>
> public static DocumentBuilder getDocumentBuilder(){
> try{
>
>
>
> DocumentBuilderFactory docbF =
> DocumentBuilderFactory.newInstance();
> DocumentBuilder docb = docbF.newDocumentBuilder();
>
>
>
> return docb;
> }catch(javax.xml.parsers.ParserConfigurationException e){
> System.out.println("ERROR Configuracion Parser : " + e);
> return null;
> }
> }
> }
> When I add a Text node and the String I am adding has null value, I get the
> Exception that you can see above. I know I should never add a null String
> value,
> but thar happends sometimes...
> I think it should be better if instead of return an null pointer exception,
> you
> control this posibility and change the null value by an empty string.
> I get the next exception :
> 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)
> at
> org.yokin.test.TestTransformerFactory.toString(TestTransformerFactory.java:76)
> at
> org.yokin.test.TestTransformerFactory.main(TestTransformerFactory.java:58)
--
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]