{"record":{"id":"9fba4260975990e2","repo":"baomidou/mybatis-plus","slug":"unable-to-create-directory","errorCode":null,"errorMessage":"Unable to create directory {}","messagePattern":"Unable to create directory (.+?)","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"mybatis-plus-generator/src/main/java/com/baomidou/mybatisplus/generator/util/FileUtils.java","lineNumber":56,"sourceCode":"     */\n    public static void forceMkdir(final File directory) throws IOException {\n        if (directory.exists()) {\n            if (!directory.isDirectory()) {\n                final String message =\n                    \"File \"\n                        + directory\n                        + \" exists and is \"\n                        + \"not a directory. Unable to create directory.\";\n                throw new IOException(message);\n            }\n        } else {\n            if (!directory.mkdirs()) {\n                // Double-check that some other thread or process hasn't made\n                // the directory in the background\n                if (!directory.isDirectory()) {\n                    final String message =\n                        \"Unable to create directory \" + directory;\n                    throw new IOException(message);\n                }\n            }\n        }\n    }\n\n    /**\n     * Makes any necessary but nonexistent parent directories for a given File. If the parent directory cannot be\n     * created then an IOException is thrown.\n     *\n     * @param file file with parent to create, must not be {@code null}\n     * @throws NullPointerException if the file is {@code null}\n     * @throws IOException          if the parent directory cannot be created\n     * @since 2.5\n     */\n    public static void forceMkdirParent(final File file) throws IOException {\n        final File parent = file.getParentFile();\n        if (parent == null) {\n            return;","sourceCodeStart":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/baomidou/mybatis-plus/blob/bf67d907478c724120bf76292da54abf9e73c2b3/mybatis-plus-generator/src/main/java/com/baomidou/mybatisplus/generator/util/FileUtils.java#L38-L74","documentation":"FileUtils.forceMkdir throws IOException when File.mkdirs() returns false AND a re-check confirms the directory still does not exist. This means the OS refused creation: a parent is not writable, a path component is a file, permissions are missing, or (rarely) a race deleted it between the two checks.","triggerScenarios":"Generating into a read-only or permission-restricted outputDir (e.g. '/' or '/opt/app' as non-root), a path where some intermediate component exists as a file, or sandboxed CI containers with a read-only filesystem layer.","commonSituations":"Running the generator in Docker/CI where the working dir is read-only; outputDir configured from a property that resolves to a path the current user cannot create; NFS mount with root_squash denying mkdir.","solutions":["Manually run `mkdir -p <path from message>` to get the real OS error (permission denied vs file exists).","Choose an outputDir under a location you own (project target/, build dir) or grant write permission to the user running the generator.","If a path component is a file, remove/rename it (see sibling error 67)."],"exampleFix":"# before (read-only path)\nglobalConfig.setOutputDir(\"/opt/app/src-gen\");\n\n# after\nglobalConfig.setOutputDir(System.getProperty(\"user.dir\") + \"/build/src-gen\");","handlingStrategy":"validation","validationCode":"File dir = new File(outputDir).getAbsoluteFile();\nif (!dir.exists() && !dir.mkdirs()) {\n    throw new IllegalStateException(\"no write permission for outputDir: \" + dir\n        + \" (writable=\" + dir.getParentFile().canWrite() + \")\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    generator.generate();\n} catch (RuntimeException e) {\n    if (e.getCause() instanceof IOException io && io.getMessage().startsWith(\"Unable to create directory\")) {\n        log.error(\"fix permissions on output dir; message names the path\");\n    }\n}","preventionTips":["Generate into project-local build directories, not system paths like /opt or /.","In Docker/CI, mount a writable volume for the output dir.","Verify the process user's write permission on every path component (mkdir -p dry run) in setup scripts."],"tags":["mybatis-plus","code-generator","filesystem","permissions","io"],"backgroundTag":null,"analyzedSha":"bf67d907478c724120bf76292da54abf9e73c2b3","analyzedAt":"2026-08-14T15:17:09.543Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}