[jdom-interest] Bug in XMLOutputter or Element.addAttribute depending on whether null is valid
Scott M Stark
Scott_Stark at displayscape.com
Tue Nov 14 23:34:15 PST 2000
The Element class allows one to add an attribute with a null value. However, when you
try to output such an element with the XMLOutputter it crashes because it does not
protect against attributes having null values. This is with the jdom b5 release.
bash-2.04$ cat tstOut.java
import java.io.*;
import org.jdom.*;
import org.jdom.output.*;
class tstOut
{
public static void main(String[] args) throws Exception
{
Element root = new Element("ProjectInfo");
root.addAttribute("name", "project1");
root.addAttribute("description", null);
Document doc = new Document(root);
XMLOutputter output = new XMLOutputter(" ");
output.output(doc, new FileOutputStream("out.xml"));
}
}
bash-2.04$ java -classpath ".;build/jdom.jar" tstOut
Exception in thread "main" java.lang.NullPointerException
at org.jdom.output.XMLOutputter.escapeAttributeEntities(XMLOutputter.java:1143)
at org.jdom.output.XMLOutputter.printAttributes(XMLOutputter.java:1125)
at org.jdom.output.XMLOutputter.printElement(XMLOutputter.java:907)
at org.jdom.output.XMLOutputter.output(XMLOutputter.java:522)
at org.jdom.output.XMLOutputter.output(XMLOutputter.java:494)
at org.jdom.output.XMLOutputter.output(XMLOutputter.java:453)
at tstOut.main(tstOut.java:14)
bash-2.04$
More information about the jdom-interest
mailing list