apache/flink · error · RuntimeException
File {} exists and overwriting is not allowed
Error message
File {} exists and overwriting is not allowed What it means
ParameterTool.createPropertiesFile(path, overwrite) refuses to clobber an existing file when overwrite is false, throwing RuntimeException after the exists() check. With overwrite=true it deletes the existing file first. The method then writes the tool's defaultData as a properties file.
Source
Thrown at flink-core/src/main/java/org/apache/flink/util/ParameterTool.java:271
public void createPropertiesFile(String pathToFile) throws IOException {
createPropertiesFile(pathToFile, true);
}
/**
* Create a properties file with all the known parameters (call after the last get*() call). Set
* the default value, if overwrite is true.
*
* @param pathToFile Location of the default properties file.
* @param overwrite Boolean flag indicating whether or not to overwrite the file
* @throws IOException If overwrite is not allowed and the file exists
*/
public void createPropertiesFile(String pathToFile, boolean overwrite) throws IOException {
final File file = new File(pathToFile);
if (file.exists()) {
if (overwrite) {
file.delete();
} else {
throw new RuntimeException(
"File " + pathToFile + " exists and overwriting is not allowed");
}
}
final Properties defaultProps = new Properties();
defaultProps.putAll(this.defaultData);
try (final OutputStream out = new FileOutputStream(file)) {
defaultProps.store(
out, "Default file created by Flink's ParameterUtil.createPropertiesFile()");
}
}
@Override
protected Object clone() throws CloneNotSupportedException {
return new ParameterTool(this.data);
}
// ------------------------- Interaction with other ParameterUtils -------------------------
View on GitHub (pinned to 2f3c205e92)
Solutions
- Pass overwrite=true if regenerating the file is intended.
- Or delete/archive the existing file before re-running the setup step.
- Make creation conditional: only call createPropertiesFile when the file is absent.
Example fix
// before params.createPropertiesFile(path, false); // second run throws // after params.createPropertiesFile(path, true); // or: if (!new File(path).exists()) params.createPropertiesFile(path, false);
Defensive patterns
Strategy: validation
Validate before calling
File f = new File(pathToFile);
if (f.exists()) { /* archive or reuse existing file instead of recreating */ } else { params.createPropertiesFile(pathToFile, false); } Prevention
- Make setup steps idempotent: skip creation when the file exists.
- Delete generated default files in cleanup between test/deploy runs.
When it happens
Trigger: Calling createPropertiesFile(path, false) when path already exists — e.g. re-running a job initialization step on the same machine without cleanup.
Common situations: Idempotent-looking setup code executed twice (retry, restart, re-deploy); shared state dir between runs; scripts that do not remove generated config between executions.
Related errors
- Properties file {} does not exist
- Configuration cannot evaluate value %s as a byte[] value
- Value for config option %s must be one of %s (was %s)
- Could not parse value for key '%s'.
- Could not parse value '%s' for key '%s'.
AI-assisted analysis of apache/flink@2f3c205e92 (2026-08-14).
Data as JSON: /api/errors/e3e26823c14699cb.
Report an issue: GitHub.