{"record":{"id":"ee8d3207b6764fcb","repo":"quarkusio/quarkus","slug":"project-path-needs-to-point-to-a-directory-targ","errorCode":null,"errorMessage":"Project path needs to point to a directory: + targetDirectory","messagePattern":"Project path needs to point to a directory: \\+ targetDirectory","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"independent-projects/tools/codestarts/src/main/java/io/quarkus/devtools/codestarts/core/CodestartProcessor.java","lineNumber":71,"sourceCode":"        codestart.use(l -> {\n            final Map<String, Object> finalData = CodestartData.buildCodestartData(codestart, languageName, data);\n            log.debug(\"codestart data: %s\", finalData);\n            Stream.of(BASE_LANGUAGE, languageName)\n                    .filter(l::dirExists)\n                    .forEach(languageDir -> processLanguageDir(projectResource, l, languageDir, finalData));\n        });\n    }\n\n    public void checkTargetDir() throws IOException {\n        if (!Files.exists(targetDirectory)) {\n            boolean mkdirStatus = targetDirectory.toFile().mkdirs();\n            if (!mkdirStatus) {\n                throw new IOException(\"Failed to create the project directory: \" + targetDirectory);\n            }\n            return;\n        }\n        if (!Files.isDirectory(targetDirectory)) {\n            throw new IOException(\"Project path needs to point to a directory: \" + targetDirectory);\n        }\n        final String[] files = targetDirectory.toFile().list();\n        if (files != null && files.length > 0) {\n            throw new IOException(\"You can't create a project when the directory is not empty: \" + targetDirectory);\n        }\n    }\n\n    public void writeFiles() throws IOException {\n        for (Map.Entry<String, List<TargetFile>> e : files.entrySet()) {\n            final String relativePath = e.getKey();\n            final CodestartFileStrategyHandler strategy = getStrategy(relativePath).orElse(getSelectedDefaultStrategy());\n            log.debug(\"processing file '%s' with strategy %s\", relativePath, strategy.name());\n            strategy.process(targetDirectory, relativePath, e.getValue(), data);\n        }\n    }\n\n    public static List<CodestartFileStrategy> buildStrategies(Map<String, String> spec) {\n        final List<CodestartFileStrategy> codestartFileStrategyHandlers = new ArrayList<>(spec.size());","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/independent-projects/tools/codestarts/src/main/java/io/quarkus/devtools/codestarts/core/CodestartProcessor.java#L53-L89","documentation":"CodestartProcessor.checkTargetDir() throws IOException('Project path needs to point to a directory: <targetDirectory>') when the given target path exists but is a regular file (or other non-directory), so a project cannot be generated into it.","triggerScenarios":"Passing an existing file path as the target directory for project generation — checkTargetDir finds Files.exists() true but Files.isDirectory() false.","commonSituations":"Typoed output path pointing at an existing file; reusing a path variable that holds a file; shell completion or scripts resolving to a file.","solutions":["Point the generation target at a new (or existing empty) directory path instead of a file.","Remove or rename the file currently occupying the intended directory path.","Validate the target path is a directory before invoking project generation."],"exampleFix":"// before\nPath target = Path.of(\"/home/user/notes.txt\");\ngenerateProject(target, ...); // IOException\n// after\nPath target = Path.of(\"/home/user/projects/my-app\");\ngenerateProject(target, ...);","handlingStrategy":"validation","validationCode":"Path target = Path.of(dest);\nif (Files.exists(target) && !Files.isDirectory(target)) {\n    throw new IllegalArgumentException(\"Target exists and is not a directory: \" + target);\n}","typeGuard":"boolean isUsableTargetDir(Path p) {\n    return p != null && (!java.nio.file.Files.exists(p) || java.nio.file.Files.isDirectory(p));\n}","tryCatchPattern":"try {\n    processor.generateProject(...);\n} catch (IOException e) {\n    if (e.getMessage().startsWith(\"Project path needs to point to a directory\")) {\n        logger.error(\"Target is a file, choose a directory path: \" + targetDir);\n    }\n    throw e;\n}","preventionTips":["Validate the target path is a directory (or doesn't exist) before generation.","Beware typoed paths that resolve to existing files.","Resolve relative paths against an explicit base directory in scripts."],"tags":["filesystem","path","io","project-generation"],"backgroundTag":"target-not-a-directory","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}