{"record":{"id":"e07625879cd7e9aa","repo":"quarkusio/quarkus","slug":"you-can-t-create-a-project-when-the-directory-is-n","errorCode":null,"errorMessage":"You can't create a project when the directory is not empty: + targetDirectory","messagePattern":"You can't create a project when the directory is not empty: \\+ 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":75,"sourceCode":"                    .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());\n\n        for (Map.Entry<String, String> entry : spec.entrySet()) {\n            final CodestartFileStrategyHandler handler = CodestartFileStrategyHandler.BY_NAME.get(entry.getValue());\n            if (handler == null) {","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/independent-projects/tools/codestarts/src/main/java/io/quarkus/devtools/codestarts/core/CodestartProcessor.java#L57-L93","documentation":"CodestartProcessor.checkTargetDir validates the target directory before generating project files. This error means the given path exists, is a directory, but already contains files, so generating a project would risk overwriting existing content. The library refuses to proceed to protect the existing directory contents.","triggerScenarios":"Calling generateProject (via CodestartProjectGeneration/CodestartLoader APIs or quarkus CLI create) into an existing, non-empty directory.","commonSituations":"Running project generation twice into the same folder; generating into a folder that already contains a git repo, README, or IDE files; accidentally pointing targetDir at the parent project directory.","solutions":["Empty the target directory (remove or move its contents) and re-run generation","Choose a different, empty or non-existent target directory","Pre-check the directory yourself with Files.list and abort or warn the user before calling generate"],"exampleFix":"// before\ngenerate.generateProject(targetDir);\n// after\ntry (Stream<Path> s = Files.list(targetDir)) {\n    if (s.findAny().isPresent()) {\n        throw new IllegalStateException(\"Target dir must be empty: \" + targetDir);\n    }\n}\ngenerate.generateProject(targetDir);","handlingStrategy":"validation","validationCode":"try (Stream<Path> s = Files.list(targetDir)) {\n    if (s.findAny().isPresent()) throw new IllegalStateException(\"Target dir not empty: \" + targetDir);\n} else if (!Files.isDirectory(targetDir)) {\n    throw new IllegalStateException(\"Target path is not a directory: \" + targetDir);\n}","typeGuard":null,"tryCatchPattern":"try {\n    generate.generateProject(targetDir);\n} catch (IOException e) {\n    if (e.getMessage() != null && e.getMessage().startsWith(\"You can't create a project when the directory is not empty\")) {\n        // clean up or choose a different directory, then retry\n    } else throw e;\n}","preventionTips":["Always generate into fresh paths","Check directory emptiness before calling generateProject","Confirm with users in tooling before writing into existing dirs"],"tags":["io","filesystem","project-generation"],"backgroundTag":"target-directory-not-empty","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}