From 6a4cb0643b7d49dccbebaba8a7935331e4023022 Mon Sep 17 00:00:00 2001 From: Marc Philipp Date: Wed, 11 Dec 2024 16:46:47 +0100 Subject: [PATCH] Ensure the XMLStreamWriter is closed after use Co-authored-by: Christian Stein --- .../platform/reporting/legacy/xml/XmlReportWriter.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/junit-platform-reporting/src/main/java/org/junit/platform/reporting/legacy/xml/XmlReportWriter.java b/junit-platform-reporting/src/main/java/org/junit/platform/reporting/legacy/xml/XmlReportWriter.java index b9d7ea13aff3..4ea8c2f8f6ac 100644 --- a/junit-platform-reporting/src/main/java/org/junit/platform/reporting/legacy/xml/XmlReportWriter.java +++ b/junit-platform-reporting/src/main/java/org/junit/platform/reporting/legacy/xml/XmlReportWriter.java @@ -115,10 +115,12 @@ private boolean shouldInclude(TestPlan testPlan, TestIdentifier testIdentifier) private void writeXmlReport(TestIdentifier testIdentifier, Map tests, Writer out) throws XMLStreamException { - new XmlReport(out).write(testIdentifier, tests); + try (XmlReport report = new XmlReport(out)) { + report.write(testIdentifier, tests); + } } - class XmlReport implements AutoCloseable { + private class XmlReport implements AutoCloseable { private final XMLStreamWriter xml; private final ReplacingWriter out;