{"id":"55c2760bc913d776","repo":"junit-team/junit5","slug":"failed-to-create-xml-events-file","errorCode":null,"errorMessage":"Failed to create XML events file","messagePattern":"Failed to create XML events file","errorType":"exception","errorClass":"JUnitException","httpStatus":null,"severity":"error","filePath":"junit-platform-reporting/src/main/java/org/junit/platform/reporting/open/xml/OpenTestReportGeneratingListener.java","lineNumber":167,"sourceCode":"\t\t\tNamespaceRegistry namespaceRegistry) throws Exception {\n\t\treturn config.get(SOCKET_PROPERTY_NAME, Integer::valueOf) //\n\t\t\t\t.map(port -> {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tSocket socket = new Socket(InetAddress.getLoopbackAddress(), port);\n\t\t\t\t\t\tWriter writer = new OutputStreamWriter(socket.getOutputStream(), StandardCharsets.UTF_8);\n\t\t\t\t\t\treturn Events.createDocumentWriter(namespaceRegistry, writer);\n\t\t\t\t\t}\n\t\t\t\t\tcatch (Exception e) {\n\t\t\t\t\t\tthrow new JUnitException(\"Failed to connect to socket on port \" + port, e);\n\t\t\t\t\t}\n\t\t\t\t}) //\n\t\t\t\t.orElseGet(() -> {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tPath eventsXml = requireNonNull(outputDir).resolve(\"open-test-report.xml\");\n\t\t\t\t\t\treturn Events.createDocumentWriter(namespaceRegistry, eventsXml);\n\t\t\t\t\t}\n\t\t\t\t\tcatch (Exception e) {\n\t\t\t\t\t\tthrow new JUnitException(\"Failed to create XML events file\", e);\n\t\t\t\t\t}\n\t\t\t\t});\n\t}\n\n\tprivate boolean isEnabled(ConfigurationParameters config) {\n\t\treturn config.getBoolean(ENABLED_PROPERTY_NAME).orElse(false);\n\t}\n\n\tprivate boolean isGitEnabled(ConfigurationParameters config) {\n\t\treturn config.getBoolean(GIT_ENABLED_PROPERTY_NAME).orElse(false);\n\t}\n\n\t@SuppressWarnings(\"EmptyCatch\")\n\tprivate void reportInfrastructure(ConfigurationParameters config) {\n\t\teventsFileWriter.append(infrastructure(), infrastructure -> {\n\t\t\ttry {\n\t\t\t\tString hostName = InetAddress.getLocalHost().getHostName();\n\t\t\t\tinfrastructure.append(hostName(hostName));","sourceCodeStart":149,"sourceCodeEnd":185,"githubUrl":"https://github.com/junit-team/junit5/blob/956246301e03d757539f7b76dd5a91f298637563/junit-platform-reporting/src/main/java/org/junit/platform/reporting/open/xml/OpenTestReportGeneratingListener.java#L149-L185","documentation":"Thrown by OpenTestReportGeneratingListener.createDocumentWriter() (file-mode branch) as a JUnitException when Events.createDocumentWriter for open-test-report.xml under outputDir fails. Reached only when socket mode is not configured; the exception wraps the underlying I/O or XML failure.","triggerScenarios":"XML reporting enabled, no socket property set, and outputDir (from the TestPlan's OutputDirectoryCreator, rooted at OutputDir) cannot host open-test-report.xml - e.g. directory missing, read-only, or the XML writer cannot initialise the file.","commonSituations":"Output directory deleted or made read-only between discovery and execution. Disk full. Concurrent test runs colliding on the same non-unique output dir. Misconfigured junit.platform.output.dir.","solutions":["Set junit.platform.output.dir to a writable, unique directory.","Ensure the output directory persists for the whole test run (do not clean it mid-run).","Inspect getCause() for the precise I/O error.","If reporting is optional, set junit.platform.reporting.open.xml.enabled=false."],"exampleFix":"# before\njunit.platform.reporting.open.xml.enabled = true\n# output dir read-only -> JUnitException\n\n# after\njunit.platform.reporting.open.xml.enabled = true\njunit.platform.output.dir = target/test-reports-${random.uuid}","handlingStrategy":"try-catch","validationCode":"Path out = testPlan.getOutputDirectoryCreator().getRootDirectory();\nFiles.createDirectories(out);\nif (!Files.isWritable(out)) throw new IllegalStateException(\"output dir not writable: \" + out);","typeGuard":"static boolean canWriteEventsFile(Path dir) {\n    Path f = dir.resolve(\"open-test-report.xml\");\n    try { Files.createDirectories(dir); return Files.isWritable(dir); }\n    catch (IOException e) { return false; }\n}","tryCatchPattern":"try {\n    Events.createDocumentWriter(ns, outputDir.resolve(\"open-test-report.xml\"));\n} catch (Exception e) {\n    // fall back to a temp dir, or disable reporting\n}","preventionTips":["Set junit.platform.output.dir to a writable, unique path.","Keep the output dir alive for the whole run; do not delete it mid-test.","Pre-flight check disk space and permissions in CI."],"tags":["reporting","xml","filesystem","io","junit-platform"],"analyzedSha":"956246301e03d757539f7b76dd5a91f298637563","analyzedAt":"2026-08-04T19:25:17.049Z","schemaVersion":2}