{"record":{"id":"409d009005cf9d28","repo":"skylot/jadx","slug":"failed-to-list-files-in-directory-dir","errorCode":null,"errorMessage":"Failed to list files in directory: ${dir}","messagePattern":"Failed to list files in directory: (.+?)","errorType":"exception","errorClass":"JadxRuntimeException","httpStatus":null,"severity":"error","filePath":"jadx-core/src/main/java/jadx/core/utils/files/FileUtils.java","lineNumber":87,"sourceCode":"\t\t\tthrow new JadxRuntimeException(\"Failed to update temp root directory\", e);\n\t\t}\n\t}\n\n\tprivate static Path createTempRootDir() {\n\t\ttry {\n\t\t\tPath dir = Files.createTempDirectory(JADX_TMP_INSTANCE_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 root directory\", e);\n\t\t}\n\t}\n\n\tpublic static List<Path> listFiles(Path dir) {\n\t\ttry (Stream<Path> files = Files.list(dir)) {\n\t\t\treturn files.collect(Collectors.toList());\n\t\t} catch (IOException e) {\n\t\t\tthrow new JadxRuntimeException(\"Failed to list files in directory: \" + dir, e);\n\t\t}\n\t}\n\n\tpublic static List<Path> listFiles(Path dir, Predicate<? super Path> filter) {\n\t\ttry (Stream<Path> files = Files.list(dir)) {\n\t\t\treturn files.filter(filter).collect(Collectors.toList());\n\t\t} catch (IOException e) {\n\t\t\tthrow new JadxRuntimeException(\"Failed to list files in directory: \" + dir, e);\n\t\t}\n\t}\n\n\tpublic static List<Path> expandDirs(List<Path> paths) {\n\t\tList<Path> files = new ArrayList<>(paths.size());\n\t\tfor (Path path : paths) {\n\t\t\tif (Files.isDirectory(path)) {\n\t\t\t\texpandDir(path, files);\n\t\t\t} else {\n\t\t\t\tfiles.add(path);","sourceCodeStart":69,"sourceCodeEnd":105,"githubUrl":"https://github.com/skylot/jadx/blob/e738a26571d02919f01df40de93bc9a44dee4e18/jadx-core/src/main/java/jadx/core/utils/files/FileUtils.java#L69-L105","documentation":"Thrown by FileUtils.listFiles(Path) when Files.list(dir) throws an IOException. Files.list fails if the path does not exist, is not a directory (e.g., it's a regular file), or the process lacks permission to read/open the directory. The Stream is wrapped in try-with-resources so close() failures are unlikely to be the root cause.","triggerScenarios":"Calling listFiles(dir) where dir does not exist (NoSuchFileException), where dir is a regular file rather than a directory (NotDirectoryException), or where the process lacks execute/read permission on the directory (AccessDeniedException).","commonSituations":"Passing an APK or JAR file path instead of its extracted directory. A race condition where the directory was deleted between an existence check and the list call. Running jadx against a path on a network share that became unavailable. Permission denied due to restrictive umask or ACL.","solutions":["Pre-check: Files.isDirectory(dir) and Files.isReadable(dir) before calling listFiles.","Log or handle the specific cause (NoSuchFileException vs AccessDeniedException) from the JadxRuntimeException to guide the fix.","If expanding an input set, filter out non-directory paths before calling listFiles.","Verify the path is not a file masquerading as a directory name."],"exampleFix":"// before\nList<Path> files = FileUtils.listFiles(dir);\n\n// after\nif (!Files.isDirectory(dir) || !Files.isReadable(dir)) {\n    return Collections.emptyList();\n}\nList<Path> files = FileUtils.listFiles(dir);","handlingStrategy":"validation","validationCode":"public static boolean isListableDir(Path dir) {\n    return Files.isDirectory(dir) && Files.isReadable(dir);\n}","typeGuard":null,"tryCatchPattern":"try {\n    List<Path> files = FileUtils.listFiles(dir);\n} catch (JadxRuntimeException e) {\n    Throwable cause = e.getCause();\n    if (cause instanceof NoSuchFileException) return Collections.emptyList();\n    if (cause instanceof NotDirectoryException) return Collections.emptyList();\n    throw e;\n}","preventionTips":["Check Files.isDirectory and Files.isReadable before listing.","Do not pass file paths where directory paths are expected.","Handle race conditions by catching and treating missing-dir as empty-list where appropriate."],"tags":["file-io","directory-listing","permissions","jadx"],"backgroundTag":null,"analyzedSha":"e738a26571d02919f01df40de93bc9a44dee4e18","analyzedAt":"2026-08-14T00:10:24.238Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}