diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/infrastructure/item/xml/StaxEventItemWriter.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/infrastructure/item/xml/StaxEventItemWriter.java index d190946201..6f5f415aae 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/infrastructure/item/xml/StaxEventItemWriter.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/infrastructure/item/xml/StaxEventItemWriter.java @@ -834,7 +834,7 @@ public void close(@Nullable StaxWriterCallback footerCallback, List unclo footerCallback.write(footerCallbackWriter); } delegateEventWriter.flush(); - endDocument(); + endDocument(delegateEventWriter); } catch (IOException e) { throw new ItemStreamException("Failed to write footer items", e); @@ -893,7 +893,7 @@ private void closeStream() { * @throws XMLStreamException thrown if error occurs. */ @SuppressWarnings("DataFlowIssue") - private void endDocument() throws XMLStreamException { + private void writeEndRootElement() throws XMLStreamException { // writer.writeEndDocument(); <- this doesn't work after restart // we need to write end tag of the root element manually @@ -925,4 +925,14 @@ private void setPosition(long newPosition) { } + /** + * Writes the EndDocument tag manually. + * @param writer XML event writer + * @throws XMLStreamException thrown if error occurs. + */ + protected void endDocument(XMLEventWriter writer) throws XMLStreamException { + Assert.state(this.state != null, "OutputState is not initialized"); + this.state.writeEndRootElement(); + } + }