{"record":{"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/f070c699a08b5d8393df9afd147af5c5e90bb21b/junit-platform-reporting/src/main/java/org/junit/platform/reporting/open/xml/OpenTestReportGeneratingListener.java#L149-L185","documentation":"Thrown as a JUnitException by OpenTestReportGeneratingListener.createDocumentWriter() (orElseGet branch) when Events.createDocumentWriter() fails to create or write the open-test-report.xml file under the root output directory. This is the DEFAULT transport — it fires only when junit.platform.reporting.open.xml.socket is NOT set. The output directory comes from TestPlan.getOutputDirectoryCreator().getRootDirectory(), which honors junit.platform.reporting.output.dir. Normally surfaces wrapped as error 145.","triggerScenarios":"The root output directory is read-only, has been deleted, or lives on a full volume at testPlanExecutionStarted time; Events.createDocumentWriter() cannot open the XML file for writing because a file lock is held by another process; the path is on a network mount that dropped; the directory creation succeeded earlier but the volume became unwritable.","commonSituations":"Read-only container layer for the default build/target dir; CI workspace cleaned between phases; antivirus locking the new XML file on Windows; NFS outage; junit.platform.reporting.output.dir pointing at a path whose parent is not writable.","solutions":["Set junit.platform.reporting.output.dir to a writable absolute path, e.g. -Djunit.platform.reporting.output.dir=/tmp/junit-reports.","Confirm Files.isWritable(root) on the directory returned by the OutputDirectoryCreator before the run.","Free disk space on the volume hosting the output directory.","Disable any process that locks files in the output directory (search indexers, AV) or move the output off a network mount."],"exampleFix":"// before\n-Djunit.platform.reporting.output.dir=/readonly/build/reports\n\n// after\n-Djunit.platform.reporting.output.dir=/var/tmp/junit-reports","handlingStrategy":"validation","validationCode":"// Preflight: confirm the creator's root directory is writable before launch.\nPath root = testPlan.getOutputDirectoryCreator().getRootDirectory();\nif (!Files.isDirectory(root) || !Files.isWritable(root)) {\n    throw new IllegalStateException(\n        \"XML events root directory not writable: \" + root);\n}","typeGuard":null,"tryCatchPattern":"try {\n    launcher.execute(request);\n} catch (JUnitException e) {\n    if (\"Failed to create XML events file\".equals(e.getMessage())) {\n        Throwable cause = e.getCause();\n        // Resolve output dir and either fix permissions or switch junit.platform.reporting.output.dir.\n    } else {\n        throw e;\n    }\n}","preventionTips":["Set junit.platform.reporting.output.dir to an absolute, writable, local path.","Add a preflight Files.isWritable check on the OutputDirectoryCreator root in CI.","Keep the volume under the output directory stable and non-full for the whole run.","Avoid regular files shadowing the open-test-report.xml path."],"tags":["filesystem","io","reporting","xml","permissions"],"backgroundTag":null,"analyzedSha":"f070c699a08b5d8393df9afd147af5c5e90bb21b","analyzedAt":"2026-08-11T20:31:00.530Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}