[JAXP-75] XMLStreamWriterImpl does not close last empty tag in fragment Created: 24/Dec/12  Updated: 24/Dec/12

Status: Open
Project: jaxp
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Major
Reporter: kevinoid Assignee: Unassigned
Resolution: Unresolved Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 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.


Generated at Sat Mar 28 11:47:42 UTC 2015 using JIRA 6.2.3#6260-sha1:63ef1d6dac3f4f4d7db4c1effd405ba38ccdc558.