spring-projects/spring-boot · error · ReportableException

{} '{}' already exists. Use --force if you want to overwrite

Error message

{} '{}' already exists. Use --force if you want to overwrite or specify an alternate location.

What it means

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.

Source

Thrown at cli/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/init/ProjectGenerator.java:124

			fixExecutableFlag(outputDirectory, "gradlew");
			Log.info("Project extracted to '" + outputDirectory.getAbsolutePath() + "'");
		}
	}

	private void extractFromStream(ZipInputStream zipStream, boolean overwrite, File outputDirectory)
			throws IOException {
		ZipEntry entry = zipStream.getNextEntry();
		String canonicalOutputPath = outputDirectory.getCanonicalPath() + File.separator;
		while (entry != null) {
			File file = new File(outputDirectory, entry.getName());
			String canonicalEntryPath = file.getCanonicalPath();
			if (!canonicalEntryPath.startsWith(canonicalOutputPath)) {
				throw new ReportableException("Entry '" + entry.getName() + "' would be written to '"
						+ canonicalEntryPath + "'. This is outside the output location of '" + canonicalOutputPath
						+ "'. Verify your target server configuration.");
			}
			if (file.exists() && !overwrite) {
				throw new ReportableException((file.isDirectory() ? "Directory" : "File") + " '" + file.getName()
						+ "' already exists. Use --force if you want to overwrite or "
						+ "specify an alternate location.");
			}
			if (!entry.isDirectory()) {
				FileCopyUtils.copy(StreamUtils.nonClosing(zipStream), new FileOutputStream(file));
			}
			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) {

View on GitHub (pinned to 270dfe353f)

Solutions

  1. Pass --force to overwrite existing files
  2. Choose a different --output directory
  3. Remove or rename the conflicting existing files first

Example fix

// before
$ spring init --extract
// after
$ spring init --extract --force
Defensive patterns

Strategy: validation

Validate before calling

// Before extracting, check the target directory is clear or pass force.
java.io.File out = (request.getOutput() != null) ? new File(request.getOutput()) : new File(".");
boolean conflict = java.util.Arrays.stream(out.listFiles())
    .anyMatch(java.io.File::exists);
if (conflict && !force) {
    throw new IllegalStateException("Output not empty - pass --force or choose another --output");
}

Try / catch

try {
    generator.generateProject(request, force);
} catch (ReportableException ex) {
    String m = ex.getMessage();
    if (m.contains("already exists")) {
        Log.error("Target not empty - rerun with --force or a different --output");
    }
    throw ex;
}

Prevention

When it happens

Trigger: Extracting a generated project into a directory where files of the same name already exist, without --force.

Common situations: Re-running 'spring init --extract' into the same output directory; extracting over an existing project skeleton.

Related errors


AI-assisted analysis of spring-projects/spring-boot@270dfe353f (2026-08-11). Data as JSON: /api/errors/798dad5a90d437b7. Report an issue: GitHub.