junit-team/junit5 · error · ExtensionConfigurationException

Failed to create default temp directory

Error message

Failed to create default temp directory

What it means

Thrown as ExtensionConfigurationException by createTempDir when constructing the CloseablePath (which calls factory.createTempDirectory) raises any Exception. This is the top-level failure path for @TempDir setup - whatever factory was configured (default, via @TempDir(factory=...), or via the global default factory supplier) failed to materialize a directory.

Solutions

  1. Ensure java.io.tmpdir is writable and has free space (echo $TMPDIR; df -h $TMPDIR; chmod/check perms).
  2. If using @TempDir(factory=CustomFactory.class), verify the factory's createTempDirectory does not throw and returns a real directory.
  3. Override the default factory via junit.jupiter.tempdir.factory.default to one targeting a writable base dir.
  4. Grant FilePermission for the chosen temp base under a SecurityManager.

Example fix

// before
@Test
void writes(@TempDir Path dir) { } // fails: TMPDIR read-only
// after - point tmpdir somewhere writable via system property
//   -Djava.io.tmpdir=$WORKSPACE/tmp
// or supply a custom factory
@Test
void writes(@TempDir(factory = WorkspaceFactory.class) Path dir) { }

public static class WorkspaceFactory implements TempDirFactory {
    @Override public Path createTempDirectory(AnnotatedElementContext ctx, ExtensionContext ec) throws IOException {
        return Files.createTempDirectory(Path.of(System.getenv("WORKSPACE_TMP")), "junit");
    }
}
Defensive patterns

Strategy: validation

Validate before calling

Path tmp = Path.of(System.getProperty("java.io.tmpdir"));
if (!Files.isWritable(tmp)) {
    throw new IllegalStateException("java.io.tmpdir not writable: " + tmp);
}

Prevention

When it happens

Trigger: new CloseablePath(...) throws inside its constructor (e.g. IOException creating the dir, security exception, factory throws); createTempDir catches Exception and wraps. Reach this when the temp dir factory cannot create a directory.

Common situations: Default java.nio.file.Files.createTempDirectory failing because TMPDIR is read-only, full, or noexec; custom TempDirFactory throwing; running in a sandboxed container with no /tmp access; CI runner with exhausted inode/disk; security manager denying FilePermission.

Related errors


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

Appendix: source

Thrown at junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/extension/TempDirectory.java:241

			TempDirFactory factory, Cleanup cleanup, ExtensionContext extensionContext) {

		Path path = extensionContext.getStore(NAMESPACE.append(elementContext)) //
				.computeIfAbsent(KEY,
					__ -> createTempDir(factory, cleanup, elementType, elementContext, extensionContext),
					CloseablePath.class) //
				.get();

		return (elementType == Path.class) ? path : path.toFile();
	}

	static CloseablePath createTempDir(TempDirFactory factory, Cleanup cleanup, Class<?> elementType,
			AnnotatedElementContext elementContext, ExtensionContext extensionContext) {

		try {
			return new CloseablePath(factory, cleanup, elementType, elementContext, extensionContext);
		}
		catch (Exception ex) {
			throw new ExtensionConfigurationException("Failed to create default temp directory", ex);
		}
	}

	private static boolean selfOrChildFailed(ExtensionContext context) {
		return context.getExecutionException().isPresent() //
				|| getContextSpecificStore(context).getOrDefault(CHILD_FAILED, Boolean.class, false);
	}

	private static ExtensionContext.Store getContextSpecificStore(ExtensionContext context) {
		return context.getStore(NAMESPACE.append(context));
	}

	@SuppressWarnings("deprecation")
	static class CloseablePath implements Store.CloseableResource, AutoCloseable {

		private final @Nullable Path dir;
		private final TempDirFactory factory;
		private final Cleanup cleanup;

View on GitHub (pinned to f070c699a0)