{"record":{"id":"28c90410c7ed4e5c","repo":"spring-projects/spring-boot","slug":"failed-to-delete-existing-file","errorCode":null,"errorMessage":"Failed to delete existing file {}","messagePattern":"Failed to delete existing file (.+?)","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":148,"sourceCode":"\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) {\n\t\t\t\tthrow new ReportableException(\n\t\t\t\t\t\t\"File '\" + outputFile.getName() + \"' already exists. Use --force if you want to \"\n\t\t\t\t\t\t\t\t+ \"overwrite or specify an alternate location.\");\n\t\t\t}\n\t\t\tif (!outputFile.delete()) {\n\t\t\t\tthrow new ReportableException(\"Failed to delete existing file \" + outputFile.getPath());\n\t\t\t}\n\t\t}\n\t\tbyte[] content = entity.getContent();\n\t\tAssert.state(content != null, \"'content' must not be null\");\n\t\tFileCopyUtils.copy(content, outputFile);\n\t\tLog.info(\"Content saved to '\" + output + \"'\");\n\t}\n\n\tprivate void fixExecutableFlag(File dir, String fileName) {\n\t\tFile f = new File(dir, fileName);\n\t\tif (f.exists()) {\n\t\t\tf.setExecutable(true, false);\n\t\t}\n\t}\n\n}\n","sourceCodeStart":130,"sourceCodeEnd":165,"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#L130-L165","documentation":"Thrown by ProjectGenerator.writeProject when --force was given but outputFile.delete() returned false - the existing output file could not be removed. The OS-level delete failed due to permissions, a lock, or the path being a non-empty directory.","triggerScenarios":"Overwrite mode on, but the target file is locked by another process, read-only, or the path names a non-empty directory; File.delete() returns false.","commonSituations":"The output file is open in another application (IDE, editor, file manager); the user lacks write/delete permission; --output accidentally names a directory.","solutions":["Close any program holding the file open (editor, IDE, file manager)","Check and fix filesystem permissions on the file and parent directory","Ensure --output names a file, not a non-empty directory","Delete the file manually, then re-run"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Before overwriting, confirm the file is actually deletable.\njava.io.File out = new java.io.File(System.getProperty(\"user.dir\"), request.getOutput());\nif (out.exists()) {\n    if (!out.canWrite()) {\n        throw new IllegalStateException(\"No write permission on \" + out);\n    }\n    if (out.isDirectory() && out.list().length > 0) {\n        throw new IllegalStateException(\"--output is a non-empty directory: \" + out);\n    }\n}","typeGuard":null,"tryCatchPattern":"try {\n    generator.generateProject(request, force);\n} catch (ReportableException ex) {\n    if (ex.getMessage().startsWith(\"Failed to delete existing file\")) {\n        Log.error(\"Could not delete existing output - close editors and check permissions: \"\n            + ex.getMessage());\n    }\n    throw ex;\n}","preventionTips":["Close any editor/IDE/file manager that may hold the output file","Confirm write+delete permissions on the output directory","Never point --output at a non-empty directory","Delete the file manually if the CLI cannot"],"tags":["initializr","file-output","permissions","io","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"}