My app writes a lot of XML data, and randomly the last line of the following piece of code:
// Prepare the DOM document for writing
Source source = new DOMSource(node);
// Prepare the output stream
Result result = new StreamResult(stream);
// Write the DOM document to the file
Transformer xformer = TransformerFactory.newInstance().newTransformer();
xformer.transform(source, result);
..throws..
javax.xml.transform.TransformerException: java.io.IOException: Detected invalid substitute UTF-16: da89 4f ?
(additionally, I don't know why, but this exception is the only one raised by the vm in my language, Portuguese, as "Detectado substituto UTF-16 inválido", I've translated it to "Detected invalid UTF-16 substitute")
Another strange thing is that I'm using UTF-8, not UTF-16, in my texts, I've checked it. And, I believe if the UTF was the problem, it would not cause randomly exception, as I'm getting the same amount of text to transform to XML.
This exception is difficult to reproduce, as it does not occur always, and it occurs when transforming lots of data to XML.
Any idea what is happening here?