baomidou/mybatis-plus · warning · IllegalArgumentException

Illegal directory {}

Error message

Illegal directory {}

What it means

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.

Source

Thrown at mybatis-plus-generator/src/main/java/com/baomidou/mybatisplus/generator/util/RuntimeUtils.java:44

 * 运行工具类
 *
 * @author nieqiurong 2020/11/13.
 * @since 3.5.0
 */
public class RuntimeUtils {

    private static final Logger LOGGER = LoggerFactory.getLogger(RuntimeUtils.class);

    /**
     * 打开指定输出文件目录
     *
     * @param outDir 输出文件目录
     */
    public static void openDir(String outDir) throws IOException {
        File file = new File(outDir);
        if (!file.isDirectory()) {
            LOGGER.error("illegal directory:{}", outDir);
            throw new IllegalArgumentException("Illegal directory " + outDir);
        }
        String osName = System.getProperty("os.name");
        if (osName != null) {
            if (osName.contains("Mac")) {
                Runtime.getRuntime().exec("open " + outDir);
            } else if (osName.contains("Windows")) {
                Runtime.getRuntime().exec(MessageFormat.format("cmd /c start \"\" \"{0}\"", outDir));
            } else {
                LOGGER.debug("file output directory:{}", outDir);
            }
        } else {
            LOGGER.warn("read operating system failed!");
        }
    }
}

View on GitHub (pinned to bf67d90747)

Solutions

  1. Disable the open-directory convenience option (it is a dev nicety, not required for generation).
  2. Pass an absolute outputDir that the generator actually wrote to and verify it exists before calling openDir.
  3. Ensure outDir is created (the generator normally force-mkdirs it) — if it is missing, generation itself likely failed earlier; check the previous logs.

Example fix

// before
RuntimeUtils.openDir(relativeOutDir); // cwd-dependent, may not exist

// after
File dir = new File(relativeDir).getAbsoluteFile();
if (dir.isDirectory()) {
    RuntimeUtils.openDir(dir.getPath());
}
Defensive patterns

Strategy: validation

Validate before calling

File dir = new File(outDir).getAbsoluteFile();
if (!dir.isDirectory()) {
    // skip the convenience open instead of failing the whole run
    log.warn("skip openDir, not a directory: {}", dir);
} else {
    RuntimeUtils.openDir(dir.getPath());
}

Try / catch

try { RuntimeUtils.openDir(outDir); } catch (IllegalArgumentException e) { log.warn("openDir skipped: {}", e.getMessage()); }

Prevention

When it happens

Trigger: 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.

Common situations: 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).

Related errors


AI-assisted analysis of baomidou/mybatis-plus@bf67d90747 (2026-08-14). Data as JSON: /api/errors/6df36d66e176af14. Report an issue: GitHub.