quarkusio/quarkus · error · IllegalArgumentException

Could not create directory ${dir}

Error message

Could not create directory ${dir}

What it means

createOutputDirectory wraps any IOException from Files.createDirectories into an IllegalArgumentException reporting the requested target directory. It is thrown when the directory for a generated project cannot be created (missing permissions, invalid path, or a non-directory file occupying the path).

Source

Thrown at independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/commands/CreateProjectHelper.java:162

    public static Path checkProjectRootPath(Path outputPath, String name) {
        requireNonNull(name, "Must specify project name");
        requireNonNull(outputPath, "Must specify output path");

        Path projectRootPath = outputPath.resolve(name);
        if (projectRootPath.toFile().exists()) {
            throw new IllegalArgumentException(
                    "Target directory already exists: " + projectRootPath.toAbsolutePath().toString());
        }
        return projectRootPath;
    }

    public static Path createOutputDirectory(String targetDirectory) {
        Path origin = new File(System.getProperty("user.dir")).toPath();
        Path outputPath = (targetDirectory == null ? origin : origin.resolve(targetDirectory));
        try {
            Files.createDirectories(outputPath);
        } catch (IOException e) {
            throw new IllegalArgumentException("Could not create directory " + targetDirectory, e);
        }
        return outputPath;
    }

    public static Set<String> sanitizeExtensions(Set<String> extensions) {
        if (extensions == null) {
            return extensions = Set.of();
        }
        return extensions.stream().filter(Objects::nonNull).map(String::trim).collect(Collectors.toSet());
    }

    public static void addSourceTypeExtensions(Set<String> extensions, SourceType sourceType) {
        if (sourceType == SourceType.KOTLIN) {
            extensions.add("quarkus-kotlin");
        }
    }

    public static void handleSpringConfiguration(Map<String, Object> values) {

View on GitHub (pinned to e1c734241f)

Solutions

  1. Check that the target directory path does not collide with an existing file and its parent is writable
  2. Run the create command from a writable directory or pass an explicit writable output dir
  3. Pre-create/verify the directory manually with mkdir -p and correct permissions
  4. Catch IllegalArgumentException and surface the underlying IOException cause for details

Example fix

// before
Path p = CreateProjectHelper.createOutputDirectory("~/myapp"); // '~' not expanded -> weird dir
// after
String dir = System.getProperty("user.home") + "/myapp";
Path p = CreateProjectHelper.createOutputDirectory(dir);
Defensive patterns

Strategy: validation

Validate before calling

Path out = targetDir == null ? Path.of(System.getProperty("user.dir")) : Path.of(System.getProperty("user.dir")).resolve(targetDir);
if (Files.exists(out) && !Files.isDirectory(out)) throw new IllegalStateException("Path exists and is not a directory: " + out);
Path parent = out.toAbsolutePath().getParent();
if (parent == null || !Files.isWritable(parent)) throw new IllegalStateException("Parent not writable: " + parent);

Type guard

static boolean isCreatableDir(Path p) {
    return !Files.exists(p) || Files.isDirectory(p);
}

Try / catch

try { Path p = CreateProjectHelper.createOutputDirectory(dir); } catch (IllegalArgumentException e) { log.error("Cannot create dir: " + dir, e.getCause()); }

Prevention

When it happens

Trigger: Calling CreateProjectHelper.createOutputDirectory with a targetDirectory that cannot be created: path segment is an existing regular file, parent dirs unwritable, or path contains illegal characters. Called during 'quarkus create' project generation.

Common situations: User passes a bad -o/--output-dir; running from a read-only cwd; a file named like the target dir already exists; network-mounted or Windows-reserved paths.

Related errors


AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05). Data as JSON: /api/errors/150570d5944ded20. Report an issue: GitHub.