{"record":{"id":"58d95f727954d70d","repo":"skylot/jadx","slug":"failed-to-clear-directory-cleardir","errorCode":null,"errorMessage":"Failed to clear directory ${clearDir}","messagePattern":"Failed to clear directory (.+?)","errorType":"exception","errorClass":"JadxRuntimeException","httpStatus":null,"severity":"warning","filePath":"jadx-core/src/main/java/jadx/core/utils/files/FileUtils.java","lineNumber":237,"sourceCode":"\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/**\n\t * Deprecated.\n\t * Migrate to {@link IJadxFilesGetter} from jadx args to get temp dir\n\t */\n\t@Deprecated\n\tpublic static Path createTempDir(String prefix) {\n\t\ttry {\n\t\t\tPath dir = Files.createTempDirectory(tempRootDir, prefix);\n\t\t\tdir.toFile().deleteOnExit();\n\t\t\treturn dir;\n\t\t} catch (Exception e) {\n\t\t\tthrow new JadxRuntimeException(\"Failed to create temp directory with suffix: \" + prefix, e);\n\t\t}\n\t}\n","sourceCodeStart":219,"sourceCodeEnd":255,"githubUrl":"https://github.com/skylot/jadx/blob/e738a26571d02919f01df40de93bc9a44dee4e18/jadx-core/src/main/java/jadx/core/utils/files/FileUtils.java#L219-L255","documentation":"Thrown by clearDir(Path) when the underlying deleteDir(clearDir, true) throws. clearDir differs from deleteDir in that it keeps the root directory (keepRootDir=true, removing the root from the deletion list). The wrapped exception originates from Files.walkFileTree failing to traverse the directory, meaning the directory does not exist, is not readable, or has permission issues during traversal.","triggerScenarios":"Calling clearDir on a path that does not exist or is not a directory. Permission denied when trying to read or delete contents. Filesystem errors during walkFileTree traversal of the directory tree.","commonSituations":"Calling clearDir on a temp directory that was already cleaned up by clearTempRootDir or an external process. A file handle still open inside the directory on Windows preventing deletion. Permission mismatch where files were created by a different OS user. Network share disconnection during traversal.","solutions":["Guard with Files.isDirectory(clearDir) before calling.","Use clearTempRootDir() which already has an isDirectory guard, if you are clearing the default temp root.","Close all open file handles before clearing on Windows.","Check the cause to distinguish 'not found' from 'permission denied'."],"exampleFix":"// before\nFileUtils.clearDir(workDir);\n\n// after\nif (Files.isDirectory(workDir)) {\n    FileUtils.clearDir(workDir);\n}","handlingStrategy":"validation","validationCode":"public static boolean isClearableDir(Path dir) {\n    return Files.isDirectory(dir) && Files.isReadable(dir);\n}","typeGuard":null,"tryCatchPattern":"try {\n    FileUtils.clearDir(dir);\n} catch (JadxRuntimeException e) {\n    if (e.getCause() instanceof NoSuchFileException) return;\n    LOG.warn(\"could not clear dir {}: {}\", dir, e.getCause().getMessage());\n}","preventionTips":["Guard with Files.isDirectory before clearing.","Use clearTempRootDir() which already has an isDirectory guard if clearing the default temp root.","Close all file handles before clearing on Windows."],"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"}