junit-team/junit5 · error · UncheckedIOException
Failed to close XML events file
Error message
Failed to close XML events file
What it means
Thrown as an UncheckedIOException by OpenTestReportGeneratingListener.testPlanExecutionFinished() when DocumentWriter.close() raises an IOException while flushing/closing the events XML document at the end of the test plan. The finally block resets eventsFileWriter to DocumentWriter.noop(), so the listener will not NPE on subsequent callbacks — but the report file may be truncated or malformed (missing closing tags). Because it is thrown at the very end of execution, test results have already been produced; the impact is on report completeness.
Solutions
- Inspect the wrapped IOException cause for the specific failure (disk full, broken pipe, closed channel).
- Ensure adequate disk space for the entire run, not just the start.
- Keep the output directory on a stable local volume; avoid network mounts for long runs.
- If using the socket transport, ensure the consumer stays alive until it receives the end-of-plan close.
Defensive patterns
Strategy: try-catch
Try / catch
// Thrown during testPlanExecutionFinished; propagates through the launcher.
try {
launcher.execute(request);
} catch (UncheckedIOException e) {
if ("Failed to close XML events file".equals(e.getMessage())) {
// Report may be truncated/malformed. Warn but do not fail the build if tests passed.
log.warn("Open-test-report.xml may be incomplete: {}", e.getCause().getMessage());
} else {
throw e;
}
} Prevention
- Ensure disk space is sufficient for the entire run, not just at start.
- Keep the output directory on a stable local volume; avoid network mounts.
- If using the socket transport, keep the consumer alive until it receives the close event.
- Exclude the output directory from antivirus scanning to prevent close-time locks.
When it happens
Trigger: The underlying stream fails during the final flush: disk full while writing the tail of the XML; the output file was deleted or its directory unmounted mid-run; on the socket transport, the remote consumer closed the connection before the test plan finished; a file channel was invalidated by the OS.
Common situations: Disk fills up during a long test run; antivirus quarantines the XML file as it is being finalized (Windows); the socket consumer crashed between start and finish of the plan; a network volume dropped mid-run; the JVM is being forcibly shut down and the channel is already closed.
Related errors
- Failed to create XML events file
- Failed to create output dir
- Failed to create output file
- Failed to initialize XML events writer
- Failed to start process
AI-assisted analysis of junit-team/junit5@f070c699a0 (2026-08-11).
Data as JSON: /api/errors/21fe7ff0cb4a80b6.
Report an issue: GitHub.
Appendix: 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 f070c699a0)