junit-team/junit5 · error · JUnitException

Failed to initialize XML events writer

Error message

Failed to initialize XML events writer

What it means

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.

Solutions

  1. Read the wrapped cause (getCause()) and its message — it tells you whether to fix the socket (146), the file/ dir (147), or git (144).
  2. If you do not need Open Test Reporting XML output, disable the listener: -Djunit.platform.reporting.open.xml.enabled=false.
  3. Ensure the output directory from TestPlan.getOutputDirectoryCreator().getRootDirectory() is writable before the run.
  4. If using the socket transport, confirm the consumer server is listening on loopback before launching tests.

Example fix

// before
-Djunit.platform.reporting.open.xml.enabled=true  // (with broken output dir / missing git / dead socket)

// after
-Djunit.platform.reporting.open.xml.enabled=false
Defensive patterns

Strategy: try-catch

Try / catch

// The listener is a TestExecutionListener; its exception propagates through the launcher.
try {
    launcher.execute(request);
} catch (JUnitException e) {
    if ("Failed to initialize XML events writer".equals(e.getMessage())) {
        Throwable cause = e.getCause();
        // Dispatch on cause: socket (connect) / file (IO) / git (process).
        log.error("Open XML report init failed due to: {}", cause, cause);
    } else {
        throw e;
    }
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of junit-team/junit5@f070c699a0 (2026-08-11). Data as JSON: /api/errors/158a42f566e1d60d. Report an issue: GitHub.

Appendix: source

Thrown at junit-platform-reporting/src/main/java/org/junit/platform/reporting/open/xml/OpenTestReportGeneratingListener.java:143

	}

	@Override
	public void testPlanExecutionStarted(TestPlan testPlan) {
		ConfigurationParameters config = testPlan.getConfigurationParameters();
		if (isEnabled(config)) {
			NamespaceRegistry namespaceRegistry = NamespaceRegistry.builder(Namespace.REPORTING_CORE) //
					.add("e", Namespace.REPORTING_EVENTS) //
					.add("git", Namespace.REPORTING_GIT) //
					.add("java", Namespace.REPORTING_JAVA) //
					.add("junit", JUnitFactory.NAMESPACE, "https://schemas.junit.org/open-test-reporting/junit-1.9.xsd") //
					.build();
			outputDir = testPlan.getOutputDirectoryCreator().getRootDirectory();
			try {
				eventsFileWriter = createDocumentWriter(config, namespaceRegistry);
				reportInfrastructure(config);
			}
			catch (Exception e) {
				throw new JUnitException("Failed to initialize XML events writer", e);
			}
		}
	}

	private DocumentWriter<Events> createDocumentWriter(ConfigurationParameters config,
			NamespaceRegistry namespaceRegistry) throws Exception {
		return config.get(SOCKET_PROPERTY_NAME, Integer::valueOf) //
				.map(port -> {
					try {
						Socket socket = new Socket(InetAddress.getLoopbackAddress(), port);
						Writer writer = new OutputStreamWriter(socket.getOutputStream(), StandardCharsets.UTF_8);
						return Events.createDocumentWriter(namespaceRegistry, writer);
					}
					catch (Exception e) {
						throw new JUnitException("Failed to connect to socket on port " + port, e);
					}
				}) //
				.orElseGet(() -> {

View on GitHub (pinned to f070c699a0)