{"record":{"id":"21fe7ff0cb4a80b6","repo":"junit-team/junit5","slug":"failed-to-close-xml-events-file","errorCode":null,"errorMessage":"Failed to close XML events file","messagePattern":"Failed to close XML events file","errorType":"exception","errorClass":"UncheckedIOException","httpStatus":null,"severity":"error","filePath":"junit-platform-reporting/src/main/java/org/junit/platform/reporting/open/xml/OpenTestReportGeneratingListener.java","lineNumber":222,"sourceCode":"\t\tgit.getOriginUrl() //\n\t\t\t\t.ifPresent(\n\t\t\t\t\tgitUrl -> infrastructure.append(repository(), repository -> repository.withOriginUrl(gitUrl)));\n\t\tgit.getBranch() //\n\t\t\t\t.ifPresent(branch -> infrastructure.append(branch(branch)));\n\t\tgit.getCommitHash() //\n\t\t\t\t.ifPresent(gitCommitHash -> infrastructure.append(commit(gitCommitHash)));\n\t\tgit.getStatus() //\n\t\t\t\t.ifPresent(statusOutput -> infrastructure.append(status(statusOutput),\n\t\t\t\t\tstatus -> status.withClean(statusOutput.isEmpty())));\n\t}\n\n\t@Override\n\tpublic void testPlanExecutionFinished(TestPlan testPlan) {\n\t\ttry {\n\t\t\teventsFileWriter.close();\n\t\t}\n\t\tcatch (IOException e) {\n\t\t\tthrow new UncheckedIOException(\"Failed to close XML events file\", e);\n\t\t}\n\t\tfinally {\n\t\t\teventsFileWriter = DocumentWriter.noop();\n\t\t}\n\t}\n\n\t@Override\n\tpublic void executionSkipped(TestIdentifier testIdentifier, String reason) {\n\t\tString id = String.valueOf(idCounter.incrementAndGet());\n\t\treportStarted(testIdentifier, id);\n\t\teventsFileWriter.append(finished(id, Instant.now()), //\n\t\t\tfinished -> finished.append(result(Result.Status.SKIPPED), result -> {\n\t\t\t\tif (isNotBlank(reason)) {\n\t\t\t\t\tresult.append(reason(reason));\n\t\t\t\t}\n\t\t\t}));\n\t}\n","sourceCodeStart":204,"sourceCodeEnd":240,"githubUrl":"https://github.com/junit-team/junit5/blob/f070c699a08b5d8393df9afd147af5c5e90bb21b/junit-platform-reporting/src/main/java/org/junit/platform/reporting/open/xml/OpenTestReportGeneratingListener.java#L204-L240","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// Thrown during testPlanExecutionFinished; propagates through the launcher.\ntry {\n    launcher.execute(request);\n} catch (UncheckedIOException e) {\n    if (\"Failed to close XML events file\".equals(e.getMessage())) {\n        // Report may be truncated/malformed. Warn but do not fail the build if tests passed.\n        log.warn(\"Open-test-report.xml may be incomplete: {}\", e.getCause().getMessage());\n    } else {\n        throw e;\n    }\n}","preventionTips":["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."],"tags":["io","reporting","xml","cleanup","flush"],"backgroundTag":null,"analyzedSha":"f070c699a08b5d8393df9afd147af5c5e90bb21b","analyzedAt":"2026-08-11T20:31:00.530Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}