{"record":{"id":"6df36d66e176af14","repo":"baomidou/mybatis-plus","slug":"illegal-directory","errorCode":null,"errorMessage":"Illegal directory {}","messagePattern":"Illegal directory (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"warning","filePath":"mybatis-plus-generator/src/main/java/com/baomidou/mybatisplus/generator/util/RuntimeUtils.java","lineNumber":44,"sourceCode":" * 运行工具类\n *\n * @author nieqiurong 2020/11/13.\n * @since 3.5.0\n */\npublic class RuntimeUtils {\n\n    private static final Logger LOGGER = LoggerFactory.getLogger(RuntimeUtils.class);\n\n    /**\n     * 打开指定输出文件目录\n     *\n     * @param outDir 输出文件目录\n     */\n    public static void openDir(String outDir) throws IOException {\n        File file = new File(outDir);\n        if (!file.isDirectory()) {\n            LOGGER.error(\"illegal directory:{}\", outDir);\n            throw new IllegalArgumentException(\"Illegal directory \" + outDir);\n        }\n        String osName = System.getProperty(\"os.name\");\n        if (osName != null) {\n            if (osName.contains(\"Mac\")) {\n                Runtime.getRuntime().exec(\"open \" + outDir);\n            } else if (osName.contains(\"Windows\")) {\n                Runtime.getRuntime().exec(MessageFormat.format(\"cmd /c start \\\"\\\" \\\"{0}\\\"\", outDir));\n            } else {\n                LOGGER.debug(\"file output directory:{}\", outDir);\n            }\n        } else {\n            LOGGER.warn(\"read operating system failed!\");\n        }\n    }\n}\n","sourceCodeStart":26,"sourceCodeEnd":60,"githubUrl":"https://github.com/baomidou/mybatis-plus/blob/bf67d907478c724120bf76292da54abf9e73c2b3/mybatis-plus-generator/src/main/java/com/baomidou/mybatisplus/generator/util/RuntimeUtils.java#L26-L60","documentation":"RuntimeUtils.openDir throws IllegalArgumentException when the given output directory string is not an existing directory. This helper is called after generation (openDirController / GlobalConfig open option) to launch the OS file explorer on the output folder; it refuses to 'open' a missing or file path. It logs 'illegal directory:{}' first, then throws.","triggerScenarios":"GlobalConfig/openDir-style option enabled with an outDir that was never created, was deleted after generation, or points to a file; also when output went to a jar/classpath location that never materialized on disk.","commonSituations":"Enabling the 'open output dir after generation' convenience flag in an environment where the dir is cleaned between runs; using relative outDir while the process cwd changed (e.g. launched from a different working directory in CI).","solutions":["Disable the open-directory convenience option (it is a dev nicety, not required for generation).","Pass an absolute outputDir that the generator actually wrote to and verify it exists before calling openDir.","Ensure outDir is created (the generator normally force-mkdirs it) — if it is missing, generation itself likely failed earlier; check the previous logs."],"exampleFix":"// before\nRuntimeUtils.openDir(relativeOutDir); // cwd-dependent, may not exist\n\n// after\nFile dir = new File(relativeDir).getAbsoluteFile();\nif (dir.isDirectory()) {\n    RuntimeUtils.openDir(dir.getPath());\n}","handlingStrategy":"validation","validationCode":"File dir = new File(outDir).getAbsoluteFile();\nif (!dir.isDirectory()) {\n    // skip the convenience open instead of failing the whole run\n    log.warn(\"skip openDir, not a directory: {}\", dir);\n} else {\n    RuntimeUtils.openDir(dir.getPath());\n}","typeGuard":null,"tryCatchPattern":"try { RuntimeUtils.openDir(outDir); } catch (IllegalArgumentException e) { log.warn(\"openDir skipped: {}\", e.getMessage()); }","preventionTips":["Treat open-dir as optional: disable it in CI/headless environments.","Always pass an absolute path derived from the same File used as outputDir.","Verify the generation output exists before invoking the convenience open."],"tags":["mybatis-plus","code-generator","filesystem","developer-experience"],"backgroundTag":null,"analyzedSha":"bf67d907478c724120bf76292da54abf9e73c2b3","analyzedAt":"2026-08-14T15:17:09.543Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}