{"record":{"id":"158a42f566e1d60d","repo":"junit-team/junit5","slug":"failed-to-initialize-xml-events-writer","errorCode":null,"errorMessage":"Failed to initialize XML events writer","messagePattern":"Failed to initialize XML events writer","errorType":"exception","errorClass":"JUnitException","httpStatus":null,"severity":"error","filePath":"junit-platform-reporting/src/main/java/org/junit/platform/reporting/open/xml/OpenTestReportGeneratingListener.java","lineNumber":143,"sourceCode":"\t}\n\n\t@Override\n\tpublic void testPlanExecutionStarted(TestPlan testPlan) {\n\t\tConfigurationParameters config = testPlan.getConfigurationParameters();\n\t\tif (isEnabled(config)) {\n\t\t\tNamespaceRegistry namespaceRegistry = NamespaceRegistry.builder(Namespace.REPORTING_CORE) //\n\t\t\t\t\t.add(\"e\", Namespace.REPORTING_EVENTS) //\n\t\t\t\t\t.add(\"git\", Namespace.REPORTING_GIT) //\n\t\t\t\t\t.add(\"java\", Namespace.REPORTING_JAVA) //\n\t\t\t\t\t.add(\"junit\", JUnitFactory.NAMESPACE, \"https://schemas.junit.org/open-test-reporting/junit-1.9.xsd\") //\n\t\t\t\t\t.build();\n\t\t\toutputDir = testPlan.getOutputDirectoryCreator().getRootDirectory();\n\t\t\ttry {\n\t\t\t\teventsFileWriter = createDocumentWriter(config, namespaceRegistry);\n\t\t\t\treportInfrastructure(config);\n\t\t\t}\n\t\t\tcatch (Exception e) {\n\t\t\t\tthrow new JUnitException(\"Failed to initialize XML events writer\", e);\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate DocumentWriter<Events> createDocumentWriter(ConfigurationParameters config,\n\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(() -> {","sourceCodeStart":125,"sourceCodeEnd":161,"githubUrl":"https://github.com/junit-team/junit5/blob/f070c699a08b5d8393df9afd147af5c5e90bb21b/junit-platform-reporting/src/main/java/org/junit/platform/reporting/open/xml/OpenTestReportGeneratingListener.java#L125-L161","documentation":"Thrown as a JUnitException by OpenTestReportGeneratingListener.testPlanExecutionStarted() via a broad catch (Exception) wrapping any failure raised while creating the DocumentWriter and while reporting infrastructure (host name, user, OS, cpu, git). It is the top-level initialization failure for the Open Test Reporting XML listener. The wrapped cause (getCause()) is the key to diagnosing the real problem — typically one of errors 144, 146, or 147.","triggerScenarios":"Any exception inside the try block at testPlanExecutionStarted: createDocumentWriter() failing on a socket (146) or file (147) problem; reportInfrastructure() triggering GitInfoCollector which throws UncheckedIOException when the git process cannot start (144); InetAddress.getLocalHost() failures (these are swallowed); or Events.createDocumentWriter() raising a schema/IO error. Only fires when junit.platform.reporting.open.xml.enabled is true.","commonSituations":"Output directory not writable (default file writer path); junit.platform.reporting.open.xml.socket set to a port with no listener; git collection enabled without git installed; container with no hostname resolution (swallowed) combined with another issue; disk full at the start of the run.","solutions":["Read the wrapped cause (getCause()) and its message — it tells you whether to fix the socket (146), the file/ dir (147), or git (144).","If you do not need Open Test Reporting XML output, disable the listener: -Djunit.platform.reporting.open.xml.enabled=false.","Ensure the output directory from TestPlan.getOutputDirectoryCreator().getRootDirectory() is writable before the run.","If using the socket transport, confirm the consumer server is listening on loopback before launching tests."],"exampleFix":"// before\n-Djunit.platform.reporting.open.xml.enabled=true  // (with broken output dir / missing git / dead socket)\n\n// after\n-Djunit.platform.reporting.open.xml.enabled=false","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// The listener is a TestExecutionListener; its exception propagates through the launcher.\ntry {\n    launcher.execute(request);\n} catch (JUnitException e) {\n    if (\"Failed to initialize XML events writer\".equals(e.getMessage())) {\n        Throwable cause = e.getCause();\n        // Dispatch on cause: socket (connect) / file (IO) / git (process).\n        log.error(\"Open XML report init failed due to: {}\", cause, cause);\n    } else {\n        throw e;\n    }\n}","preventionTips":["Always inspect getCause() — it identifies the real file/socket/git failure.","Run a preflight that checks output-dir writability, git availability (if enabled), and socket reachability (if set).","Disable the listener with junit.platform.reporting.open.xml.enabled=false when XML output is not required.","Pin the open-test-reporting and junit-platform-reporting versions together."],"tags":["reporting","xml","listener","initialization","wrapper"],"backgroundTag":null,"analyzedSha":"f070c699a08b5d8393df9afd147af5c5e90bb21b","analyzedAt":"2026-08-11T20:31:00.530Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}