{"record":{"id":"798dad5a90d437b7","repo":"spring-projects/spring-boot","slug":"already-exists-use-force-if-you-want-to","errorCode":null,"errorMessage":"{} '{}' already exists. Use --force if you want to overwrite or specify an alternate location.","messagePattern":"(.+?) '(.+?)' already exists\\. Use --force if you want to overwrite or specify an alternate location\\.","errorType":"exception","errorClass":"ReportableException","httpStatus":null,"severity":"error","filePath":"cli/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/init/ProjectGenerator.java","lineNumber":124,"sourceCode":"\t\t\tfixExecutableFlag(outputDirectory, \"gradlew\");\n\t\t\tLog.info(\"Project extracted to '\" + outputDirectory.getAbsolutePath() + \"'\");\n\t\t}\n\t}\n\n\tprivate void extractFromStream(ZipInputStream zipStream, boolean overwrite, File outputDirectory)\n\t\t\tthrows IOException {\n\t\tZipEntry entry = zipStream.getNextEntry();\n\t\tString canonicalOutputPath = outputDirectory.getCanonicalPath() + File.separator;\n\t\twhile (entry != null) {\n\t\t\tFile file = new File(outputDirectory, entry.getName());\n\t\t\tString canonicalEntryPath = file.getCanonicalPath();\n\t\t\tif (!canonicalEntryPath.startsWith(canonicalOutputPath)) {\n\t\t\t\tthrow new ReportableException(\"Entry '\" + entry.getName() + \"' would be written to '\"\n\t\t\t\t\t\t+ canonicalEntryPath + \"'. This is outside the output location of '\" + canonicalOutputPath\n\t\t\t\t\t\t+ \"'. Verify your target server configuration.\");\n\t\t\t}\n\t\t\tif (file.exists() && !overwrite) {\n\t\t\t\tthrow new ReportableException((file.isDirectory() ? \"Directory\" : \"File\") + \" '\" + file.getName()\n\t\t\t\t\t\t+ \"' already exists. Use --force if you want to overwrite or \"\n\t\t\t\t\t\t+ \"specify an alternate location.\");\n\t\t\t}\n\t\t\tif (!entry.isDirectory()) {\n\t\t\t\tFileCopyUtils.copy(StreamUtils.nonClosing(zipStream), new FileOutputStream(file));\n\t\t\t}\n\t\t\telse {\n\t\t\t\tfile.mkdir();\n\t\t\t}\n\t\t\tzipStream.closeEntry();\n\t\t\tentry = zipStream.getNextEntry();\n\t\t}\n\t}\n\n\tprivate void writeProject(ProjectGenerationResponse entity, String output, boolean overwrite) throws IOException {\n\t\tFile outputFile = new File(System.getProperty(\"user.dir\"), output);\n\t\tif (outputFile.exists()) {\n\t\t\tif (!overwrite) {","sourceCodeStart":106,"sourceCodeEnd":142,"githubUrl":"https://github.com/spring-projects/spring-boot/blob/270dfe353fb830fd69b823a8a859287ff103854b/cli/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/init/ProjectGenerator.java#L106-L142","documentation":"Thrown by ProjectGenerator.extractFromStream when, during zip extraction, an entry's target file or directory already exists on disk and --force was not supplied. The message prefixes 'File' or 'Directory' based on the existing path type.","triggerScenarios":"Extracting a generated project into a directory where files of the same name already exist, without --force.","commonSituations":"Re-running 'spring init --extract' into the same output directory; extracting over an existing project skeleton.","solutions":["Pass --force to overwrite existing files","Choose a different --output directory","Remove or rename the conflicting existing files first"],"exampleFix":"// before\n$ spring init --extract\n// after\n$ spring init --extract --force","handlingStrategy":"validation","validationCode":"// Before extracting, check the target directory is clear or pass force.\njava.io.File out = (request.getOutput() != null) ? new File(request.getOutput()) : new File(\".\");\nboolean conflict = java.util.Arrays.stream(out.listFiles())\n    .anyMatch(java.io.File::exists);\nif (conflict && !force) {\n    throw new IllegalStateException(\"Output not empty - pass --force or choose another --output\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    generator.generateProject(request, force);\n} catch (ReportableException ex) {\n    String m = ex.getMessage();\n    if (m.contains(\"already exists\")) {\n        Log.error(\"Target not empty - rerun with --force or a different --output\");\n    }\n    throw ex;\n}","preventionTips":["Extract into a fresh dedicated directory","Pass --force only when you intend to overwrite","In CI, clean the output directory before each run"],"tags":["initializr","file-output","overwrite","validation","spring-boot-cli"],"backgroundTag":null,"analyzedSha":"270dfe353fb830fd69b823a8a859287ff103854b","analyzedAt":"2026-08-11T19:42:06.541Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}