Details
-
Bug
-
Status: Open
-
Major
-
Resolution: Unresolved
-
2.7
-
None
-
None
-
Windows, Mac OS X, Linux
Description
In some cases the Doctype gets added twice. I experienced it when serializing as HTML, but from looking at the code I see the problem is generic for serialization.
Steps to reproduce:
Since using Cocoon, I cannot provide a clean java snippet that reproduces the failure. The setup is a TransformerHandler writing into a StreamResult with output properties set to method=html (apart others):
TransformerHandler handler = this.getTransformerHandler();
handler.getTransformer().setOutputProperties(this.format);
handler.setResult(new StreamResult(this.output));
this.setContentHandler(handler);
this.setLexicalHandler(handler);
First call:
The stacktrace upon the first call is when ToHTMLStream.ignorableWhiteSpace() is called, which effectively calls startDocumentInternal() that writes out the doctype for the first time. The m_needToCallStartDocument is set to false.
Second call:
The TransformerIdentityImpl.flushStartDoc() calls ToHTMLStream.startDocument(), which calls startDocumentInternal() without checking if m_needToCallStartDocument is true or not. The doctype is added for the second time.
Proposed fix:
SerializerBase.startDocument() should call startDocumentInternal() only if m_needToCallStartDocument is true. Or, even better, include the check for m_needToCallStartDocument inside startDocumentInternal() method to prevent similar mistakes.
Maybe related to http://issues.apache.org/jira/browse/XALANJ-1685 ??