{"record":{"id":"2a45d71a5f404e5f","repo":"skylot/jadx","slug":"failed-to-delete-directory-dir","errorCode":null,"errorMessage":"Failed to delete directory ${dir}","messagePattern":"Failed to delete directory (.+?)","errorType":"exception","errorClass":"JadxRuntimeException","httpStatus":null,"severity":"warning","filePath":"jadx-core/src/main/java/jadx/core/utils/files/FileUtils.java","lineNumber":223,"sourceCode":"\t\t\t\t\t} catch (Exception e) {\n\t\t\t\t\t\tLOG.warn(\"Failed to delete file {}\", path.toAbsolutePath(), e);\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t}\n\t\t\t// after all files are deleted, remove empty directories\n\t\t\tif (keepRootDir) {\n\t\t\t\t// root dir always last\n\t\t\t\tListUtils.removeLast(directories);\n\t\t\t}\n\t\t\tfor (Path directory : directories) {\n\t\t\t\ttry {\n\t\t\t\t\tFiles.delete(directory);\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\tLOG.warn(\"Failed to delete directory {}\", directory.toAbsolutePath(), e);\n\t\t\t\t}\n\t\t\t}\n\t\t} catch (Exception e) {\n\t\t\tthrow new JadxRuntimeException(\"Failed to delete directory \" + dir, e);\n\t\t}\n\t}\n\n\tpublic static void clearTempRootDir() {\n\t\tif (Files.isDirectory(tempRootDir)) {\n\t\t\tclearDir(tempRootDir);\n\t\t}\n\t}\n\n\tpublic static void clearDir(Path clearDir) {\n\t\ttry {\n\t\t\tdeleteDir(clearDir, true);\n\t\t} catch (Exception e) {\n\t\t\tthrow new JadxRuntimeException(\"Failed to clear directory \" + clearDir, e);\n\t\t}\n\t}\n\n\t/**","sourceCodeStart":205,"sourceCodeEnd":241,"githubUrl":"https://github.com/skylot/jadx/blob/e738a26571d02919f01df40de93bc9a44dee4e18/jadx-core/src/main/java/jadx/core/utils/files/FileUtils.java#L205-L241","documentation":"Thrown by the private deleteDir(Path, boolean) when Files.walkFileTree fails to traverse the directory tree. The traversal itself throws if the root directory does not exist, or if a permission issue prevents visiting files/directories. Individual file and subdirectory delete failures during the walk are logged as warnings (LOG.warn) and do NOT throw — only the walkFileTree failure itself triggers this exception. The message includes the root dir path.","triggerScenarios":"Calling deleteDir on a path that does not exist (NoSuchFileException from walkFileTree). Calling it on a directory where the process lacks permission to read or enter subdirectories. A broken symlink or filesystem error during tree traversal.","commonSituations":"Attempting to clean up a temp directory that was already removed by another process or a prior cleanup pass. Permission denied because files inside were created by a different user. Network filesystem errors during traversal. Circular symlinks causing traversal issues (though FOLLOW_LINKS is not used here, so less likely).","solutions":["Guard with existence check: only call deleteDir if Files.exists(dir).","Use the more lenient deleteDirIfExists(Path) variant which catches exceptions internally and logs them.","Check directory readability and execute permissions before deletion.","Inspect the cause: NoSuchFileException means already gone; AccessDeniedException means a permission problem."],"exampleFix":"// before\nFileUtils.deleteDir(tempDir);\n\n// after\nif (Files.exists(tempDir)) {\n    FileUtils.deleteDir(tempDir);\n}","handlingStrategy":"fallback","validationCode":"public static boolean isDeletableDir(Path dir) {\n    return Files.exists(dir) && Files.isReadable(dir);\n}","typeGuard":null,"tryCatchPattern":"try {\n    FileUtils.deleteDir(dir);\n} catch (JadxRuntimeException e) {\n    if (e.getCause() instanceof NoSuchFileException) {\n        // already gone — not an error\n        return;\n    }\n    LOG.warn(\"could not delete dir {}: {}\", dir, e.getCause().getMessage());\n}","preventionTips":["Prefer deleteDirIfExists which swallows errors gracefully for cleanup paths.","Check existence before deleting to avoid 'not found' errors.","Ensure no open file handles (especially on Windows) before deletion."],"tags":["filesystem","cleanup","delete","permissions","jadx"],"backgroundTag":null,"analyzedSha":"e738a26571d02919f01df40de93bc9a44dee4e18","analyzedAt":"2026-08-14T00:10:24.238Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}