Uploaded image for project: 'Spring Framework'
  1. Spring Framework
  2. SPR-11254

XMLEventStreamWriter fails to handle writeEmptyElement() followed by writeAttribute()

    XMLWordPrintable

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Complete
    • 3.2.6, 4.0 GA
    • 3.2.7, 4.0.1
    • Core
    • None
    • true

    Description

      XMLEventStreamWriter converts an XMLStreamWriter into an XMLEventWriter.

      However, it fails to handle the following sequence of API calls:

        XMLStreamWriter.writeEmptyElement()
        XMLStreamWriter.writeAttribute()
      

      What happens is you get this exception:

      Caused by: javax.xml.stream.XMLStreamException: Attribute not associated with any element
              at com.sun.xml.internal.stream.writers.XMLStreamWriterImpl.writeAttribute(XMLStreamWriterImpl.java:610)
              at com.sun.xml.internal.stream.writers.XMLEventWriterImpl.add(XMLEventWriterImpl.java:164)
              at org.springframework.util.xml.XMLEventStreamWriter.writeAttribute(XMLEventStreamWriter.java:126)
      

      The problem is that the XMLEventStreamWriter implementation seems to think that "writeEmptyElement" means "write element with no attributes", whereas what it really means is "write element with no nested content" (i.e., an element that can be self-closing).

      The usage above is explicitly supported by the XMLStreamWriter API and in the JDK implementation results in a self-closing tag being emitted – with or without attributes.

      The fix is to keep track of whether the most recent element is self-closing or not.

      Attachments

        Activity

          People

            juergen.hoeller Juergen Hoeller
            archie172 Archie Cobbs
            Spring Issues Spring Issues
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              3 years, 38 weeks, 1 day ago