junit-team/junit5 · error · UncheckedIOException
Failed to close XML events file
Error message
Failed to close XML events file
What it means
Thrown by OpenTestReportGeneratingListener.testPlanExecutionFinished() as an UncheckedIOException when DocumentWriter.close() raises IOException while finalising the events XML. Occurs at the end of a test plan execution; the writer is reset to noop in a finally block but the IOException is rethrown.
Source
Thrown at junit-platform-reporting/src/main/java/org/junit/platform/reporting/open/xml/OpenTestReportGeneratingListener.java:222
git.getOriginUrl() //
.ifPresent(
gitUrl -> infrastructure.append(repository(), repository -> repository.withOriginUrl(gitUrl)));
git.getBranch() //
.ifPresent(branch -> infrastructure.append(branch(branch)));
git.getCommitHash() //
.ifPresent(gitCommitHash -> infrastructure.append(commit(gitCommitHash)));
git.getStatus() //
.ifPresent(statusOutput -> infrastructure.append(status(statusOutput),
status -> status.withClean(statusOutput.isEmpty())));
}
@Override
public void testPlanExecutionFinished(TestPlan testPlan) {
try {
eventsFileWriter.close();
}
catch (IOException e) {
throw new UncheckedIOException("Failed to close XML events file", e);
}
finally {
eventsFileWriter = DocumentWriter.noop();
}
}
@Override
public void executionSkipped(TestIdentifier testIdentifier, String reason) {
String id = String.valueOf(idCounter.incrementAndGet());
reportStarted(testIdentifier, id);
eventsFileWriter.append(finished(id, Instant.now()), //
finished -> finished.append(result(Result.Status.SKIPPED), result -> {
if (isNotBlank(reason)) {
result.append(reason(reason));
}
}));
}
View on GitHub (pinned to 956246301e)
Solutions
- Ensure the output filesystem has capacity and remains mounted for the entire run.
- In socket mode, keep the server connected until testPlanExecutionFinished completes.
- Inspect the wrapped IOException for the specific failure (broken pipe, no space, etc.).
- Disable XML reporting if the environment cannot guarantee a clean close.
Example fix
// before: disk fills during run, close() throws UncheckedIOException // after: ensure adequate disk space; or disable reporting junit.platform.reporting.open.xml.enabled = false
Defensive patterns
Strategy: try-catch
Validate before calling
// Ensure the output medium stays healthy for the whole run
long free = outputDir.toFile().getUsableSpace();
if (free < MIN_FREE_BYTES) throw new IllegalStateException("low disk: " + free); Type guard
static boolean writerLikelyCloseable(DocumentWriter<?> w) {
try { w.flush(); return true; } catch (IOException e) { return false; }
} Try / catch
try {
eventsFileWriter.close();
} catch (IOException e) {
// log and continue; the report may be partial but the run need not abort
log.warn("Failed to close XML events file: {}", e.getMessage());
} finally {
eventsFileWriter = DocumentWriter.noop();
} Prevention
- Reserve enough disk space for the entire test run before writing reports.
- In socket mode, keep the server connected until testPlanExecutionFinished finishes.
- Treat a close failure as non-fatal if partial reports are acceptable.
When it happens
Trigger: XML reporting was enabled and the events file writer fails to flush/close - e.g. the underlying file/stream was closed externally, the socket (in socket mode) dropped, or the filesystem failed the final write.
Common situations: Disk filled during the run. Socket server disconnected mid-stream in socket mode. File deleted or FS unmounted before close. Process received a signal that left the writer half-open.
Related errors
- Failed to create XML events file
- Failed to start process
- Failed to initialize XML events writer
- Could not read color palette properties
- Could not open color palette properties file
AI-assisted analysis of junit-team/junit5@956246301e (2026-08-04).
Data as JSON: /data/errors/21fe7ff0cb4a80b6.json.
Report an issue: GitHub.