{"record":{"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/f070c699a08b5d8393df9afd147af5c5e90bb21b/junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/extension/TempDirectory.java#L223-L259","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Ensure java.io.tmpdir is writable and has free space (echo $TMPDIR; df -h $TMPDIR; chmod/check perms).","If using @TempDir(factory=CustomFactory.class), verify the factory's createTempDirectory does not throw and returns a real directory.","Override the default factory via junit.jupiter.tempdir.factory.default to one targeting a writable base dir.","Grant FilePermission for the chosen temp base under a SecurityManager."],"exampleFix":"// before\n@Test\nvoid writes(@TempDir Path dir) { } // fails: TMPDIR read-only\n// after - point tmpdir somewhere writable via system property\n//   -Djava.io.tmpdir=$WORKSPACE/tmp\n// or supply a custom factory\n@Test\nvoid writes(@TempDir(factory = WorkspaceFactory.class) Path dir) { }\n\npublic static class WorkspaceFactory implements TempDirFactory {\n    @Override public Path createTempDirectory(AnnotatedElementContext ctx, ExtensionContext ec) throws IOException {\n        return Files.createTempDirectory(Path.of(System.getenv(\"WORKSPACE_TMP\")), \"junit\");\n    }\n}","handlingStrategy":"validation","validationCode":"Path tmp = Path.of(System.getProperty(\"java.io.tmpdir\"));\nif (!Files.isWritable(tmp)) {\n    throw new IllegalStateException(\"java.io.tmpdir not writable: \" + tmp);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pre-flight check that java.io.tmpdir (or junit Jupiter tempdir base) is writable in CI.","If you supply a custom @TempDir(factory=...), test it standalone.","Set junit.jupiter.tempdir.factory.default to a factory targeting a known-writable base."],"tags":["tempdir","io","factory","filesystem","extension"],"backgroundTag":null,"analyzedSha":"f070c699a08b5d8393df9afd147af5c5e90bb21b","analyzedAt":"2026-08-11T20:31:00.530Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}