{"id":"d48739d56e2cdb22","repo":"junit-team/junit5","slug":"failed-to-create-default-temp-directory","errorCode":null,"errorMessage":"Failed to create default temp directory","messagePattern":"Failed to create default temp directory","errorType":"exception","errorClass":"ExtensionConfigurationException","httpStatus":null,"severity":"error","filePath":"junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/extension/TempDirectory.java","lineNumber":241,"sourceCode":"\t\t\tTempDirFactory factory, Cleanup cleanup, ExtensionContext extensionContext) {\n\n\t\tPath path = extensionContext.getStore(NAMESPACE.append(elementContext)) //\n\t\t\t\t.computeIfAbsent(KEY,\n\t\t\t\t\t__ -> createTempDir(factory, cleanup, elementType, elementContext, extensionContext),\n\t\t\t\t\tCloseablePath.class) //\n\t\t\t\t.get();\n\n\t\treturn (elementType == Path.class) ? path : path.toFile();\n\t}\n\n\tstatic CloseablePath createTempDir(TempDirFactory factory, Cleanup cleanup, Class<?> elementType,\n\t\t\tAnnotatedElementContext elementContext, ExtensionContext extensionContext) {\n\n\t\ttry {\n\t\t\treturn new CloseablePath(factory, cleanup, elementType, elementContext, extensionContext);\n\t\t}\n\t\tcatch (Exception ex) {\n\t\t\tthrow new ExtensionConfigurationException(\"Failed to create default temp directory\", ex);\n\t\t}\n\t}\n\n\tprivate static boolean selfOrChildFailed(ExtensionContext context) {\n\t\treturn context.getExecutionException().isPresent() //\n\t\t\t\t|| getContextSpecificStore(context).getOrDefault(CHILD_FAILED, Boolean.class, false);\n\t}\n\n\tprivate static ExtensionContext.Store getContextSpecificStore(ExtensionContext context) {\n\t\treturn context.getStore(NAMESPACE.append(context));\n\t}\n\n\t@SuppressWarnings(\"deprecation\")\n\tstatic class CloseablePath implements Store.CloseableResource, AutoCloseable {\n\n\t\tprivate final @Nullable Path dir;\n\t\tprivate final TempDirFactory factory;\n\t\tprivate final Cleanup cleanup;","sourceCodeStart":223,"sourceCodeEnd":259,"githubUrl":"https://github.com/junit-team/junit5/blob/956246301e03d757539f7b76dd5a91f298637563/junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/extension/TempDirectory.java#L223-L259","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before — custom factory points at a non-writable root\nclass MyFactory implements TempDirFactory {\n    public Path createTempDirectory(AnnotatedElementContext c, ExtensionContext ec) throws Exception {\n        return Files.createDirectory(Path.of(\"/opt/readonly/junit-\" + System.nanoTime()));\n    }\n}\n// after\nclass MyFactory implements TempDirFactory {\n    public Path createTempDirectory(AnnotatedElementContext c, ExtensionContext ec) throws Exception {\n        Path base = Path.of(System.getProperty(\"java.io.tmpdir\"), \"junit\");\n        Files.createDirectories(base);\n        return Files.createTempDirectory(base, \"test-\");\n    }\n}","handlingStrategy":"validation","validationCode":"// Ensure the temp dir base is writable before launch\nPath tmp = Path.of(System.getProperty(\"java.io.tmpdir\"));\nif (!Files.isWritable(tmp)) throw new IllegalStateException(\"tmpdir not writable: \" + tmp);\ntry { Path probe = Files.createTempDirectory(tmp, \"probe-\"); Files.delete(probe); }\ncatch (IOException e) { throw new IllegalStateException(\"Cannot create temp dir under \" + tmp, e); }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["junit-jupiter","tempdir","extension","io","filesystem"],"analyzedSha":"956246301e03d757539f7b76dd5a91f298637563","analyzedAt":"2026-08-04T19:25:17.049Z","schemaVersion":2}