You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by bu...@apache.org on 2004/05/04 12:09:12 UTC
DO NOT REPLY [Bug 28762] New: -
NullPointerException in TreeWalker
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=28762>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND
INSERTED IN THE BUG DATABASE.
http://issues.apache.org/bugzilla/show_bug.cgi?id=28762
NullPointerException in TreeWalker
Summary: NullPointerException in TreeWalker
Product: XalanJ2
Version: 2.5
Platform: All
OS/Version: All
Status: NEW
Severity: Normal
Priority: Other
Component: org.apache.xml.utils
AssignedTo: xalan-dev@xml.apache.org
ReportedBy: jdiezgome@ebankinter.com
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)
---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-dev-help@xml.apache.org