Uploaded image for project: 'XalanJ2'
  1. XalanJ2
  2. XALANJ-2369

Doctype added twice when ignorableWhitespace() is called before startDocument()

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 2.7
    • None
    • Serialization
    • 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 ??

      Attachments

        Activity

          People

            Unassigned Unassigned
            alexander.klimetschek Alexander Klimetschek
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated: