{"record":{"id":"29b18bacbbd673ff","repo":"apache/flink","slug":"error-29b18b","errorCode":null,"errorMessage":"{}","messagePattern":"\\{\\}","errorType":"exception","errorClass":"FileAlreadyExistsException","httpStatus":null,"severity":"error","filePath":"flink-core/src/main/java/org/apache/flink/core/fs/local/LocalFileSystem.java","lineNumber":242,"sourceCode":"     * @return <code>true</code>if the directories either already existed or have been created\n     *     successfully, <code>false</code> otherwise\n     * @throws IOException thrown if an error occurred while creating the directory/directories\n     */\n    @Override\n    public boolean mkdirs(final Path f) throws IOException {\n        checkNotNull(f, \"path is null\");\n        return mkdirsInternal(pathToFile(f));\n    }\n\n    private boolean mkdirsInternal(File file) throws IOException {\n        if (file.isDirectory()) {\n            return true;\n        } else if (file.exists() && !file.isDirectory()) {\n            // Important: The 'exists()' check above must come before the 'isDirectory()' check to\n            //            be safe when multiple parallel instances try to create the directory\n\n            // exists and is not a directory -> is a regular file\n            throw new FileAlreadyExistsException(file.getAbsolutePath());\n        } else {\n            File parent = file.getParentFile();\n            return (parent == null || mkdirsInternal(parent))\n                    && (file.mkdir() || file.isDirectory());\n        }\n    }\n\n    @Override\n    public FSDataOutputStream create(final Path filePath, final WriteMode overwrite)\n            throws IOException {\n        checkNotNull(filePath, \"filePath\");\n\n        if (exists(filePath) && overwrite == WriteMode.NO_OVERWRITE) {\n            throw new FileAlreadyExistsException(\"File already exists: \" + filePath);\n        }\n\n        final Path parent = filePath.getParent();\n        if (parent != null && !mkdirs(parent)) {","sourceCodeStart":224,"sourceCodeEnd":260,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-core/src/main/java/org/apache/flink/core/fs/local/LocalFileSystem.java#L224-L260","documentation":"Thrown as FileAlreadyExistsException by LocalFileSystem.mkdirsInternal() when the target path exists but is NOT a directory (i.e. it is a regular file). The {} in the message is replaced by file.getAbsolutePath(). The exists() check intentionally precedes isDirectory() to be safe under parallel directory creation.","triggerScenarios":"Calling mkdirs(path) where path resolves to an existing regular file rather than a directory.","commonSituations":"Output path collides with an existing file; checkpoint dir path pointing at a file; two outputs configured to the same path with conflicting types; leftover file from a previous run blocking dir creation.","solutions":["Remove or rename the conflicting regular file at the path.","Use a distinct path for the directory that does not collide with an existing file.","In setup, assert the configured dir path does not point to a file before starting the job.","Clear stale outputs from prior runs."],"exampleFix":"// before (path /out/data exists as a file)\nfs.mkdirs(new Path(\"/out/data\"));\n\n// after\nnew File(\"/out/data\").delete(); // or rename\nfs.mkdirs(new Path(\"/out/data\"));","handlingStrategy":"validation","validationCode":"void safeMkdirs(FileSystem fs, Path p) throws IOException {\n    java.io.File f = new File(p.toUri());\n    if (f.exists() && !f.isDirectory())\n        throw new FileAlreadyExistsException(\"Path is a file, cannot mkdir: \" + p);\n    fs.mkdirs(p);\n}","typeGuard":null,"tryCatchPattern":"try {\n    fs.mkdirs(p);\n} catch (FileAlreadyExistsException e) {\n    // rename/remove the conflicting file, or pick a new dir path\n}","preventionTips":["Do not reuse file paths as directory paths.","Clean stale outputs before running jobs.","Validate path type expectations at startup."],"tags":["filesystem","local-fs","mkdir","file-conflict","configuration"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}