SourceForge.net
Sun, 02 Mar 2008 00:35:37 -0800
Bugs item #1495925, was opened at 2006-05-27 12:27 Message generated for change (Comment added) made by doogiemuc You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=116035&aid=1495925&group_id=16035 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: None Group: None Status: Open Resolution: None Priority: 5 Private: No Submitted By: Callebaut Beno�t (bencal) Assigned to: Nobody/Anonymous (nobody) Summary: DOM4J 1.6.1 xml file generation Exception Initial Comment: I use DOM4J 1.6.1 to write a custom build domcument to an XML file. It fails with a StringIndexOutOfBoundsException. If I do the same with DOM4J 1.5.1 I have no problem. My tree contains a lot of empty elements and use sometimes stange names (characters like +,-,_) Here is the code I use to write the XML file: OutputFormat outformat = OutputFormat.createPrettyPrint(); document.getRootElement().normalize(); try{ ((VFSXmlFileObject)this.getRoot()).flushChilds(); XMLWriter writer = new XMLWriter(this.getParentLayer().getContent().getOutputStream(false), outformat); writer.write(this.document); writer.flush(); writer.close(); document = null; }catch (Exception e){ e.printStackTrace(); } Here is the Exception: java.lang.StringIndexOutOfBoundsException: String index out of range: 0 [java] at java.lang.String.charAt(String.java:558) [java] at org.dom4j.io.XMLWriter.writeElementContent(XMLWriter.java:1098) [java] at org.dom4j.io.XMLWriter.writeElement(XMLWriter.java:954) [java] at org.dom4j.io.XMLWriter.writeNode(XMLWriter.java:1301) [java] at org.dom4j.io.XMLWriter.writeElementContent(XMLWriter.java:1086) [java] at org.dom4j.io.XMLWriter.writeElement(XMLWriter.java:954) [java] at org.dom4j.io.XMLWriter.writeNode(XMLWriter.java:1301) [java] at org.dom4j.io.XMLWriter.writeElementContent(XMLWriter.java:1086) [java] at org.dom4j.io.XMLWriter.writeElement(XMLWriter.java:954) [java] at org.dom4j.io.XMLWriter.writeNode(XMLWriter.java:1301) [java] at org.dom4j.io.XMLWriter.writeElementContent(XMLWriter.java:1086) [java] at org.dom4j.io.XMLWriter.writeElement(XMLWriter.java:954) [java] at org.dom4j.io.XMLWriter.writeNode(XMLWriter.java:1301) [java] at org.dom4j.io.XMLWriter.writeElementContent(XMLWriter.java:1086) [java] at org.dom4j.io.XMLWriter.writeElement(XMLWriter.java:954) [java] at org.dom4j.io.XMLWriter.writeNode(XMLWriter.java:1301) [java] at org.dom4j.io.XMLWriter.writeElementContent(XMLWriter.java:1086) [java] at org.dom4j.io.XMLWriter.writeElement(XMLWriter.java:954) [java] at org.dom4j.io.XMLWriter.writeNode(XMLWriter.java:1301) [java] at org.dom4j.io.XMLWriter.writeElementContent(XMLWriter.java:1086) [java] at org.dom4j.io.XMLWriter.writeElement(XMLWriter.java:954) [java] at org.dom4j.io.XMLWriter.writeNode(XMLWriter.java:1301) [java] at org.dom4j.io.XMLWriter.write(XMLWriter.java:344) ---------------------------------------------------------------------- Comment By: Robert Rackl (doogiemuc) Date: 2008-03-02 09:35 Message: Logged In: YES user_id=2024793 Originator: NO I have a simpler code to reproduce this bug. Its still there: import java.io.FileWriter; import java.io.IOException; import org.dom4j.Document; import org.dom4j.DocumentFactory; import org.dom4j.DocumentHelper; import org.dom4j.Element; import org.dom4j.io.OutputFormat; import org.dom4j.io.XMLWriter; public class Dom4jBug { public static void main(String[] args) { try { Document doc = DocumentHelper.createDocument(); Element rootElem = doc.addElement("root"); Element propElem = DocumentFactory.getInstance().createElement("property"); propElem.addElement("item"); propElem.setText(""); rootElem.add(propElem); OutputFormat format = OutputFormat.createPrettyPrint(); XMLWriter writer = new XMLWriter(new FileWriter("test.xml"), format); writer.write(doc); // <== throws StringIndexOutOfBoundsException !!! writer.close(); } catch (IOException ex) { ex.printStackTrace(); } } } ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=116035&aid=1495925&group_id=16035
------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________ dom4j-dev mailing list dom4j-dev@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/dom4j-dev