{"record":{"id":"7a47f5381b6eb9c5","repo":"quarkusio/quarkus","slug":"target-file-already-exists-targetpath-tostring","errorCode":null,"errorMessage":"Target file already exists: + targetPath.toString()","messagePattern":"Target file already exists: \\+ targetPath\\.toString\\(\\)","errorType":"exception","errorClass":"CodestartStructureException","httpStatus":null,"severity":"error","filePath":"independent-projects/tools/codestarts/src/main/java/io/quarkus/devtools/codestarts/core/strategy/CodestartFileStrategyHandler.java","lineNumber":47,"sourceCode":"                    new SmartPomMergeCodestartFileStrategyHandler(),\n                    new SmartPackageFileStrategyHandler(),\n                    new DockerComposeCodestartFileStrategyHandler())\n            .collect(Collectors.toMap(CodestartFileStrategyHandler::name, Function.identity()));\n\n    String name();\n\n    void process(Path targetDirectory, String relativePath, List<TargetFile> codestartFiles, Map<String, Object> data)\n            throws IOException;\n\n    default void checkNotEmptyCodestartFiles(List<TargetFile> codestartFiles) {\n        if (codestartFiles == null || codestartFiles.isEmpty()) {\n            throw new CodestartStructureException(\"codestartFiles must not be null or empty\");\n        }\n    }\n\n    default void checkTargetDoesNotExist(Path targetPath) {\n        if (Files.exists(targetPath)) {\n            throw new CodestartStructureException(\n                    \"Target file already exists: \" + targetPath.toString());\n        }\n    }\n\n    default void createDirectories(Path targetPath) throws IOException {\n        Files.createDirectories(targetPath.getParent());\n    }\n\n    default void writeFile(final Path targetPath, final String content) throws IOException {\n        if (!SKIP_FILE_IDENTIFIER.equals(content)) {\n            Files.write(targetPath, content.getBytes(StandardCharsets.UTF_8));\n        }\n    }\n\n}\n","sourceCodeStart":29,"sourceCodeEnd":63,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/independent-projects/tools/codestarts/src/main/java/io/quarkus/devtools/codestarts/core/strategy/CodestartFileStrategyHandler.java#L29-L63","documentation":"checkTargetDoesNotExist is a fail-fast guard for strategy handlers that must not overwrite files. It throws when the resolved target path already exists on disk. This prevents strategies like 'create-new' from silently clobbering user files.","triggerScenarios":"A codestart file strategy that calls checkTargetDoesNotExist runs during generation while a file already exists at targetDirectory/relativePath — typically generating into a directory with pre-existing content.","commonSituations":"Generating into a non-empty or previously generated directory; renaming files in a codestart so new files collide with old ones; running generation twice without cleaning the output.","solutions":["Clean the target directory or delete the conflicting file before regenerating","Use a different target directory for the new project","Choose a conflict strategy that permits overwrite (e.g. override) instead of one that fails on existing targets"],"exampleFix":"// before\nhandler.process(targetDir, \"pom.xml\", files, data); // pom.xml may exist\n// after\nPath p = targetDir.resolve(\"pom.xml\");\nif (Files.exists(p)) Files.delete(p);\nhandler.process(targetDir, \"pom.xml\", files, data);","handlingStrategy":"validation","validationCode":"if (Files.exists(targetDir.resolve(relativePath)))\n    throw new IllegalStateException(\"Exists: \" + relativePath);","typeGuard":null,"tryCatchPattern":"try { generate.generateProject(targetDir); }\ncatch (CodestartStructureException e) {\n    if (e.getMessage().startsWith(\"Target file already exists:\")) { /* clean or relocate */ }\n    else throw e;\n}","preventionTips":["Generate into empty dirs only","Clean stale output before regenerating","Back up files before regeneration"],"tags":["filesystem","codestart","file-conflict"],"backgroundTag":"target-file-already-exists","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"}