junit-team/junit5 · error · UncheckedIOException

Failed to create output file:

Error message

Failed to create output file: 

What it means

Thrown by OutputDir.createFile() as an UncheckedIOException when creating a uniquely-named output file fails. The method resolves prefix-random.ext under the output dir, deletes an existing file with that name if present, then calls Files.createFile; any IOException is wrapped with the offending file path in the message.

Source

Thrown at junit-platform-launcher/src/main/java/org/junit/platform/launcher/listeners/OutputDir.java:114

		this.random = random;
	}

	public Path toPath() {
		return path;
	}

	public Path createFile(String prefix, String extension) throws UncheckedIOException {
		String filename = "%s-%d.%s".formatted(prefix, positiveLong(random), extension);
		Path outputFile = path.resolve(filename);

		try {
			if (Files.exists(outputFile)) {
				Files.delete(outputFile);
			}
			return Files.createFile(outputFile);
		}
		catch (IOException e) {
			throw new UncheckedIOException("Failed to create output file: " + outputFile, e);
		}
	}

	private static long positiveLong(SecureRandom random) {
		var value = random.nextLong();
		if (value == Long.MIN_VALUE) {
			// ensure Math.abs returns positive value
			value++;
		}
		return Math.abs(value);
	}

	/**
	 * Determine if the supplied directory contains files with any of the
	 * supplied extensions.
	 */
	private static boolean containsFilesWithExtensions(Path dir, String... extensions) throws IOException {
		BiPredicate<Path, BasicFileAttributes> matcher = (path, basicFileAttributes) -> {

View on GitHub (pinned to 956246301e)

Solutions

  1. Ensure the output directory exists and is writable before triggering file creation (set junit.platform.output.dir appropriately).
  2. Check the exception message for the resolved file path and verify its parent directory.
  3. Free disk space / fix permissions on the CI agent.
  4. Avoid concurrent processes writing to the same output dir with non-unique prefixes.

Example fix

// before: output dir deleted mid-run, createFile throws

// after: ensure dir exists and is writable; set a valid output dir
junit.platform.output.dir = target/test-output
Defensive patterns

Strategy: try-catch

Validate before calling

Path parent = outputDir.toPath();
if (!Files.isDirectory(parent) || !Files.isWritable(parent)) {
    throw new IllegalStateException("output dir missing or read-only: " + parent);
}

Type guard

static boolean canCreateFile(Path dir) {
    try { Path tmp = Files.createTempFile(dir, "probe", ".tmp"); Files.delete(tmp); return true; }
    catch (IOException e) { return false; }
}

Try / catch

try {
    outputDir.createFile(prefix, ext);
} catch (UncheckedIOException e) {
    // recreate the parent dir or fall back to a temp location
}

Prevention

When it happens

Trigger: OutputDir.createFile(prefix, extension) is called when the output directory does not exist, is read-only, the filename collides in an unwritable way, or the filesystem rejects the create. The path is included in the exception message.

Common situations: Output directory was deleted between discovery and report writing. Filesystem permissions changed mid-run. Disk full. The output dir was never created because OutputDir.create targeted an invalid path but a downstream component still holds a reference.

Related errors


AI-assisted analysis of junit-team/junit5@956246301e (2026-08-04). Data as JSON: /data/errors/d37a963db23a43e3.json. Report an issue: GitHub.