{"record":{"id":"e3e26823c14699cb","repo":"apache/flink","slug":"file-exists-and-overwriting-is-not-allowed","errorCode":null,"errorMessage":"File {} exists and overwriting is not allowed","messagePattern":"File (.+?) exists and overwriting is not allowed","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"flink-core/src/main/java/org/apache/flink/util/ParameterTool.java","lineNumber":271,"sourceCode":"    public void createPropertiesFile(String pathToFile) throws IOException {\n        createPropertiesFile(pathToFile, true);\n    }\n\n    /**\n     * Create a properties file with all the known parameters (call after the last get*() call). Set\n     * the default value, if overwrite is true.\n     *\n     * @param pathToFile Location of the default properties file.\n     * @param overwrite Boolean flag indicating whether or not to overwrite the file\n     * @throws IOException If overwrite is not allowed and the file exists\n     */\n    public void createPropertiesFile(String pathToFile, boolean overwrite) throws IOException {\n        final File file = new File(pathToFile);\n        if (file.exists()) {\n            if (overwrite) {\n                file.delete();\n            } else {\n                throw new RuntimeException(\n                        \"File \" + pathToFile + \" exists and overwriting is not allowed\");\n            }\n        }\n        final Properties defaultProps = new Properties();\n        defaultProps.putAll(this.defaultData);\n        try (final OutputStream out = new FileOutputStream(file)) {\n            defaultProps.store(\n                    out, \"Default file created by Flink's ParameterUtil.createPropertiesFile()\");\n        }\n    }\n\n    @Override\n    protected Object clone() throws CloneNotSupportedException {\n        return new ParameterTool(this.data);\n    }\n\n    // ------------------------- Interaction with other ParameterUtils -------------------------\n","sourceCodeStart":253,"sourceCodeEnd":289,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-core/src/main/java/org/apache/flink/util/ParameterTool.java#L253-L289","documentation":"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.","triggerScenarios":"Calling createPropertiesFile(path, false) when path already exists — e.g. re-running a job initialization step on the same machine without cleanup.","commonSituations":"Idempotent-looking setup code executed twice (retry, restart, re-deploy); shared state dir between runs; scripts that do not remove generated config between executions.","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."],"exampleFix":"// before\nparams.createPropertiesFile(path, false); // second run throws\n\n// after\nparams.createPropertiesFile(path, true);\n// or: if (!new File(path).exists()) params.createPropertiesFile(path, false);","handlingStrategy":"validation","validationCode":"File f = new File(pathToFile);\nif (f.exists()) { /* archive or reuse existing file instead of recreating */ } else { params.createPropertiesFile(pathToFile, false); }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Make setup steps idempotent: skip creation when the file exists.","Delete generated default files in cleanup between test/deploy runs."],"tags":["configuration","file-io","flink-core"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}