{"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/956246301e03d757539f7b76dd5a91f298637563/junit-platform-reporting/src/main/java/org/junit/platform/reporting/open/xml/OpenTestReportGeneratingListener.java#L125-L161","documentation":"Thrown by OpenTestReportGeneratingListener.testPlanExecutionStarted() as a JUnitException wrapping any failure from createDocumentWriter() or reportInfrastructure(). This is the top-level guard around XML events writer initialisation (socket or file mode) plus infrastructure/git reporting. The root cause is attached as the exception's cause.","triggerScenarios":"junit.platform.reporting.open.xml.enabled=true and either the socket connection fails, the events file cannot be created, NamespaceRegistry/DocumentWriter construction fails, or reportInfrastructure throws (e.g. git process failure). The broad catch at line 142-144 wraps all of these.","commonSituations":"Misconfigured socket port, unwritable output directory, git enabled but missing, or an incompatible opentest4j-reporting library version on the classpath. Enabling XML reporting in a restricted CI environment.","solutions":["Inspect the wrapped cause (getCause()) to identify socket, file, or git failure and address that specifically.","If you do not need XML reporting, set junit.platform.reporting.open.xml.enabled=false (or leave unset).","Ensure the output directory is writable and the socket port (if set) is listening.","Align the opentest4j-reporting dependency version with the JUnit Platform version in use."],"exampleFix":"// before\njunit.platform.reporting.open.xml.enabled = true\n# output dir read-only -> JUnitException on init\n\n// after\njunit.platform.reporting.open.xml.enabled = true\njunit.platform.output.dir = target/test-reports  # writable","handlingStrategy":"try-catch","validationCode":"// Only enable XML reporting when prerequisites hold\nboolean enabled = Boolean.getBoolean(\"junit.platform.reporting.open.xml.enabled\");\nif (enabled) {\n    Path out = Path.of(System.getProperty(\"junit.platform.output.dir\", \"target\"));\n    Files.createDirectories(out);\n    if (System.getProperty(\"junit.platform.reporting.open.xml.socket\") != null\n        && !socketListening(port)) enabled = false;\n}","typeGuard":null,"tryCatchPattern":"try {\n    listener.testPlanExecutionStarted(testPlan);\n} catch (JUnitException e) {\n    // log getCause(); disable reporting or fix env; tests can still run without the listener\n    log.warn(\"XML reporting init failed: {}\", e.getMessage());\n}","preventionTips":["Inspect the wrapped cause to target the real failure (socket/file/git).","Enable XML reporting only in environments known to support it.","Keep junit-platform-reporting and opentest4j-reporting versions aligned."],"tags":["reporting","xml","listener","initialization","junit-platform"],"analyzedSha":"956246301e03d757539f7b76dd5a91f298637563","analyzedAt":"2026-08-04T19:25:17.049Z","schemaVersion":2}