jaxp
  1. jaxp
  2. JAXP-75

XMLStreamWriterImpl does not close last empty tag in fragment

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None

      Description

      When writing an XML fragment (rather than an entire document, which would have a non-empty root element), if the last call is to writeEmptyElement, the empty element is not closed. As an example, consider the following program:

      import java.io.IOException;
      import java.io.OutputStreamWriter;
      import javax.xml.stream.XMLOutputFactory;
      import javax.xml.stream.XMLStreamException;
      import javax.xml.stream.XMLStreamWriter;
      
      class XMLStreamWriterFragBugDemo {
          public static void main(String[] args) throws IOException, XMLStreamException {
      	OutputStreamWriter outWriter = new OutputStreamWriter(System.out);
      	XMLStreamWriter xmlWriter =
      	    XMLOutputFactory.newInstance().createXMLStreamWriter(outWriter);
      
      	xmlWriter.writeEmptyElement("empty");
      	xmlWriter.writeEmptyElement("empty");
      
      	xmlWriter.flush();
      	xmlWriter.close();
      
      	outWriter.flush();
      
      	System.out.println("");
          }
      }
      

      This should output <empty/><empty/>, but instead it outputs <empty/><empty.

      The fix that I would suggest is to call closeStartTag() before fWriter.flush() in close() if fStartTagOpened is true, but that is up to you, of course.

        Activity

        No work has yet been logged on this issue.

          People

          • Assignee:
            Unassigned
            Reporter:
            kevinoid
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated: