{"record":{"id":"5767edd57e7d7e21","repo":"apache/flink","slug":"directory-is-not-empty","errorCode":null,"errorMessage":"Directory {} is not empty","messagePattern":"Directory (.+?) is not empty","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"flink-core/src/main/java/org/apache/flink/core/fs/local/LocalFileSystem.java","lineNumber":186,"sourceCode":"\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\n     */\n    private boolean delete(final File f) throws IOException {\n\n        if (f.isDirectory()) {\n            final File[] files = f.listFiles();","sourceCodeStart":168,"sourceCodeEnd":204,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-core/src/main/java/org/apache/flink/core/fs/local/LocalFileSystem.java#L168-L204","documentation":"Thrown by LocalFileSystem.delete() in non-recursive mode when the target directory exists and contains files (listFiles().length != 0). It prevents accidental silent non-deletion of a non-empty directory.","triggerScenarios":"Calling delete(path, recursive=false) on a directory that contains one or more entries.","commonSituations":"Forgetting to set recursive=true when clearing an output directory; checkpoint cleanup over a partially-populated dir; output dir reuse with leftover data.","solutions":["Pass recursive=true if you intend to delete the whole tree: `fs.delete(path, true)`.","If non-recursive is intentional, empty the directory first or pick an empty target.","Configure your sink/output to use a fresh directory or set overwrite mode."],"exampleFix":"// before\nfs.delete(outputDir, false); // throws if non-empty\n\n// after\nfs.delete(outputDir, true);","handlingStrategy":"validation","validationCode":"void deleteDir(FileSystem fs, Path p, boolean recursive) throws IOException {\n    if (!recursive && fs.getFileStatus(p).isDir()) {\n        // caller must confirm emptiness or choose recursive\n    }\n    fs.delete(p, recursive);\n}","typeGuard":null,"tryCatchPattern":"try {\n    fs.delete(p, false);\n} catch (IOException e) {\n    if (e.getMessage().endsWith(\"is not empty\")) fs.delete(p, true);\n    else throw e;\n}","preventionTips":["Default to recursive=true for directory cleanup unless emptiness is guaranteed.","Clean output dirs in job setup to avoid leftover entries."],"tags":["filesystem","local-fs","delete","configuration"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}