spring-projects/spring-boot · error · ReportableException
Failed to delete existing file {}
Error message
Failed to delete existing file {} What it means
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.
Source
Thrown at cli/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/init/ProjectGenerator.java:148
}
else {
file.mkdir();
}
zipStream.closeEntry();
entry = zipStream.getNextEntry();
}
}
private void writeProject(ProjectGenerationResponse entity, String output, boolean overwrite) throws IOException {
File outputFile = new File(System.getProperty("user.dir"), output);
if (outputFile.exists()) {
if (!overwrite) {
throw new ReportableException(
"File '" + outputFile.getName() + "' already exists. Use --force if you want to "
+ "overwrite or specify an alternate location.");
}
if (!outputFile.delete()) {
throw new ReportableException("Failed to delete existing file " + outputFile.getPath());
}
}
byte[] content = entity.getContent();
Assert.state(content != null, "'content' must not be null");
FileCopyUtils.copy(content, outputFile);
Log.info("Content saved to '" + output + "'");
}
private void fixExecutableFlag(File dir, String fileName) {
File f = new File(dir, fileName);
if (f.exists()) {
f.setExecutable(true, false);
}
}
}
View on GitHub (pinned to 270dfe353f)
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
Defensive patterns
Strategy: validation
Validate before calling
// Before overwriting, confirm the file is actually deletable.
java.io.File out = new java.io.File(System.getProperty("user.dir"), request.getOutput());
if (out.exists()) {
if (!out.canWrite()) {
throw new IllegalStateException("No write permission on " + out);
}
if (out.isDirectory() && out.list().length > 0) {
throw new IllegalStateException("--output is a non-empty directory: " + out);
}
} Try / catch
try {
generator.generateProject(request, force);
} catch (ReportableException ex) {
if (ex.getMessage().startsWith("Failed to delete existing file")) {
Log.error("Could not delete existing output - close editors and check permissions: "
+ ex.getMessage());
}
throw ex;
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: The output file is open in another application (IDE, editor, file manager); the user lacks write/delete permission; --output accidentally names a directory.
Related errors
- Failed to {} from service at '{}' ({})
- Could not save the project, the server did not set a preferr
- {} '{}' already exists. Use --force if you want to overwrite
- File '{}' already exists. Use --force if you want to overwri
- Invalid content received from server ({})
AI-assisted analysis of spring-projects/spring-boot@270dfe353f (2026-08-11).
Data as JSON: /api/errors/28c90410c7ed4e5c.
Report an issue: GitHub.