{"record":{"id":"cc04a6bcf171b749","repo":"testcontainers/testcontainers-java","slug":"failed-to-create-directory-at-directory","errorCode":null,"errorMessage":"Failed to create directory at: <directory>","messagePattern":"Failed to create directory at: <directory>","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/testcontainers/utility/PathUtils.java","lineNumber":53,"sourceCode":"                    @Override\n                    public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {\n                        Files.delete(file);\n                        return FileVisitResult.CONTINUE;\n                    }\n                }\n            );\n        } catch (IOException ignored) {}\n    }\n\n    /**\n     * Make a directory, plus any required parent directories.\n     *\n     * @param directory the directory path to make\n     */\n    public static void mkdirp(Path directory) {\n        boolean result = directory.toFile().mkdirs();\n        if (!result) {\n            throw new IllegalStateException(\"Failed to create directory at: \" + directory);\n        }\n    }\n\n    /**\n     * Create a MinGW compatible path based on usual Windows path\n     *\n     * @param path a usual windows path\n     * @return a MinGW compatible path\n     */\n    public static String createMinGWPath(String path) {\n        String mingwPath = path.replace('\\\\', '/');\n        int driveLetterIndex = 1;\n        if (mingwPath.matches(\"^[a-zA-Z]:\\\\/.*\")) {\n            driveLetterIndex = 0;\n        }\n\n        // drive-letter must be lower case\n        mingwPath =","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/testcontainers/testcontainers-java/blob/8e549514e3f01c57d70546fbb8599d138f3903e5/core/src/main/java/org/testcontainers/utility/PathUtils.java#L35-L71","documentation":"PathUtils.mkdirp(Path) calls File.mkdirs() and throws IllegalStateException when it returns false. mkdirs() returns false only when the directory does not already exist AND could not be created (typically permission denied, or a parent is a regular file), since success or pre-existence both return true.","triggerScenarios":"Calling PathUtils.mkdirp(new File(\"/some/path\").toPath()) where the path's parent is a file, the user lacks write permission on the parent, or the filesystem is read-only. Used internally when Testcontainers prepares temp/Target dirs for container mounts.","commonSituations":"Mapping container paths into ./target on CI with restrictive umask; creating dirs under /var or C:\\Program Files without elevation; a path component like 'target' actually being a file after a bad build; read-only Docker bind-mount roots.","solutions":["Check that no parent path component is an existing regular file and remove/rename it","Grant write permission on the parent directory (chmod/chown) or run with sufficient privileges","Point the directory at a writable location (e.g. project target/ or java.io.tmpdir)","Ensure the directory doesn't already exist as a non-directory and the filesystem isn't read-only (mount -o rw)"],"exampleFix":"// before\nPathUtils.mkdirp(Paths.get(\"/var/lib/myapp/state\")); // may be unwritable\n// after\nPath dir = Paths.get(System.getProperty(\"java.io.tmpdir\"), \"myapp-state\");\nFiles.createDirectories(dir); // clearer error, works with pre-existing dirs\nPathUtils.mkdirp(dir);","handlingStrategy":"validation","validationCode":"Path dir = Paths.get(\"/some/state\");\nPath parent = dir.toAbsolutePath().getParent();\nif (parent != null && Files.exists(parent) && !Files.isDirectory(parent))\n    throw new IllegalStateException(\"Parent is a file: \" + parent);\nif (!Files.isWritable(parent))\n    throw new IllegalStateException(\"No write permission on: \" + parent);","typeGuard":"boolean canCreate(Path dir) {\n    Path p = dir.toAbsolutePath().getParent();\n    return p != null && Files.isDirectory(p) && Files.isWritable(p);\n}","tryCatchPattern":"try {\n    PathUtils.mkdirp(dir);\n} catch (IllegalStateException e) {\n    Files.createDirectories(dir); // surfaces a precise java.nio reason (AccessDeniedException, etc.)\n}","preventionTips":["Create test working dirs under target/ or the OS temp dir","Check CI runner umask and mount flags (no read-only roots)","Verify no path component is an existing regular file"],"tags":["filesystem","mkdir","permissions"],"backgroundTag":"mkdir-permission-denied","analyzedSha":"8e549514e3f01c57d70546fbb8599d138f3903e5","analyzedAt":"2026-09-12T14:56:41.227Z","contentChangedAt":"2026-09-12T14:56:41.227Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}