{"record":{"id":"b39be6dec060ebb0","repo":"apache/flink","slug":"directory-does-not-exist-or-an-i-o-error-occurr","errorCode":null,"errorMessage":"Directory {} does not exist or an I/O error occurred","messagePattern":"Directory (.+?) does not exist or an I/O error occurred","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"flink-core/src/main/java/org/apache/flink/core/fs/local/LocalFileSystem.java","lineNumber":181,"sourceCode":"        }\n        results = new FileStatus[names.length];\n        for (int i = 0; i < names.length; i++) {\n            results[i] = getFileStatus(new Path(f, names[i]));\n        }\n\n        return results;\n    }\n\n    @Override\n    public boolean delete(final Path f, final boolean recursive) throws IOException {\n\n        final File file = pathToFile(f);\n        if (file.isFile()) {\n            return file.delete();\n        } else if ((!recursive) && file.isDirectory()) {\n            File[] containedFiles = file.listFiles();\n            if (containedFiles == null) {\n                throw new IOException(\n                        \"Directory \"\n                                + file.toString()\n                                + \" does not exist or an I/O error occurred\");\n            } else if (containedFiles.length != 0) {\n                throw new IOException(\"Directory \" + file.toString() + \" is not empty\");\n            }\n        }\n\n        return delete(file);\n    }\n\n    /**\n     * Deletes the given file or directory.\n     *\n     * @param f the file to be deleted\n     * @return <code>true</code> if all files were deleted successfully, <code>false</code>\n     *     otherwise\n     * @throws IOException thrown if an error occurred while deleting the files/directories","sourceCodeStart":163,"sourceCodeEnd":199,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-core/src/main/java/org/apache/flink/core/fs/local/LocalFileSystem.java#L163-L199","documentation":"Thrown by LocalFileSystem.delete() when File.listFiles() returns null on a directory entry. listFiles() returns null when the path doesn't exist or an I/O error occurred (e.g. permission denied on listing). The non-recursive delete path detects this and surfaces it.","triggerScenarios":"Calling delete(path, recursive=false) on a directory that vanished between isDirectory() and listFiles(), or whose contents cannot be enumerated due to permissions/I/O.","commonSituations":"Concurrent deletion by another process; permission denied on directory listing; filesystem errors (NFS hiccup, disk failure); race between check and use.","solutions":["If intentional recursive removal, call delete(path, recursive=true) which takes a different code path.","Check and fix directory permissions so the Flink user can list it.","Guard against races by catching IOException and re-checking existence, or retry once.","Ensure no other process concurrently deletes the directory during the operation."],"exampleFix":"// before\nfs.delete(dirPath, false);\n\n// after (if recursive intended)\nfs.delete(dirPath, true);","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    fs.delete(p, false);\n} catch (IOException e) {\n    if (e.getMessage().contains(\"does not exist or an I/O error occurred\")) {\n        if (!fs.exists(p)) return; // already gone\n        // else retry with recursive or fix perms\n    }\n    throw e;\n}","preventionTips":["Use recursive=true when removing directory trees.","Ensure the Flink user can list target directories.","Avoid concurrent external deletion of managed directories."],"tags":["filesystem","local-fs","delete","permissions","race-condition"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}