junit-team/junit5 · error · ExtensionConfigurationException
Failed to create default temp directory
Error message
Failed to create default temp directory
What it means
Thrown by TempDirectory.createTempDir() when constructing a CloseablePath (which calls the configured TempDirFactory.createTempDirectory()) raises any Exception. The factory default uses Files.createTempDirectory(), so failures typically stem from the underlying filesystem; the engine wraps the cause in an ExtensionConfigurationException.
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 956246301e)
Solutions
- Inspect the cause Exception for the exact I/O error and path.
- Ensure java.io.tmpdir (or your factory's base) is writable and has free space; on CI, set -Djava.io.tmpdir to a writable volume.
- If using a custom @TempDir(factory = MyFactory.class), debug MyFactory.createTempDirectory in isolation and ensure it creates the directory and all missing parents.
- Clean up leaked temp dirs from prior runs that may have exhausted inodes/space.
Example fix
// before — custom factory points at a non-writable root
class MyFactory implements TempDirFactory {
public Path createTempDirectory(AnnotatedElementContext c, ExtensionContext ec) throws Exception {
return Files.createDirectory(Path.of("/opt/readonly/junit-" + System.nanoTime()));
}
}
// after
class MyFactory implements TempDirFactory {
public Path createTempDirectory(AnnotatedElementContext c, ExtensionContext ec) throws Exception {
Path base = Path.of(System.getProperty("java.io.tmpdir"), "junit");
Files.createDirectories(base);
return Files.createTempDirectory(base, "test-");
}
} Defensive patterns
Strategy: validation
Validate before calling
// Ensure the temp dir base is writable before launch
Path tmp = Path.of(System.getProperty("java.io.tmpdir"));
if (!Files.isWritable(tmp)) throw new IllegalStateException("tmpdir not writable: " + tmp);
try { Path probe = Files.createTempDirectory(tmp, "probe-"); Files.delete(probe); }
catch (IOException e) { throw new IllegalStateException("Cannot create temp dir under " + tmp, e); } Prevention
- Point java.io.tmpdir at a writable volume with free space (-Djava.io.tmpdir=...).
- Unit-test custom TempDirFactory implementations in isolation.
- Clean up leaked temp directories in CI between runs.
When it happens
Trigger: A custom @TempDir(factory = ...) whose createTempDirectory() throws, or the default factory failing because the java.io.tmpdir is full, read-only, or the process lacks permission to create a directory there.
Common situations: CI runners with a full /tmp; containers mounted with a read-only tmpfs; a custom TempDirFactory that creates dirs under a configured root that does not exist or is unwritable; disk quota exceeded.
Related errors
- temp directory must be a directory
- temp directory with non-default file system cannot be inject
- Failed to copy files to the output directory
- Failed to publish path
- Failed to create output directory
AI-assisted analysis of junit-team/junit5@956246301e (2026-08-04).
Data as JSON: /data/errors/d48739d56e2cdb22.json.
Report an issue: GitHub.