{"record":{"id":"4acdfca0ddd69241","repo":"skylot/jadx","slug":"desc-directory-exists-as-file-dir","errorCode":null,"errorMessage":"${desc} directory exists as file ${dir}","messagePattern":"(.+?) directory exists as file (.+?)","errorType":"validation","errorClass":"JadxArgsValidateException","httpStatus":null,"severity":"error","filePath":"jadx-core/src/main/java/jadx/api/JadxArgsValidator.java","lineNumber":90,"sourceCode":"\t\t\tif (pos != -1) {\n\t\t\t\toutDirName = name.substring(0, pos);\n\t\t\t} else {\n\t\t\t\toutDirName = name + '-' + JadxArgs.DEFAULT_OUT_DIR;\n\t\t\t}\n\t\t}\n\t\tLOG.info(\"output directory: {}\", outDirName);\n\t\treturn new File(outDirName);\n\t}\n\n\tprivate static void checkFile(File file) {\n\t\tif (!file.exists()) {\n\t\t\tthrow new JadxArgsValidateException(\"File not found \" + file.getAbsolutePath());\n\t\t}\n\t}\n\n\tprivate static void checkDir(File dir, String desc) {\n\t\tif (dir != null && dir.exists() && !dir.isDirectory()) {\n\t\t\tthrow new JadxArgsValidateException(desc + \" directory exists as file \" + dir);\n\t\t}\n\t}\n\n\tprivate JadxArgsValidator() {\n\t}\n}\n","sourceCodeStart":72,"sourceCodeEnd":97,"githubUrl":"https://github.com/skylot/jadx/blob/e738a26571d02919f01df40de93bc9a44dee4e18/jadx-core/src/main/java/jadx/api/JadxArgsValidator.java#L72-L97","documentation":"An argument-validation error from JadxArgsValidator.checkDir(), used for the output source/resource/output directories. If a directory path exists on disk but resolves to a regular file (not a directory), jadx cannot create or write into it and throws JadxArgsValidateException naming the descriptor (e.g. 'output source') and the conflicting path. This is checked during initialization.","triggerScenarios":"Setting args.setOutDirSrc()/setOutDirRes()/setOutDir() to a path that is already occupied by a file (e.g., a file named 'src' exists where jadx wants a 'src/' directory).","commonSituations":"A previous run left a regular file where a directory is now expected; a path collision where an output file and an output directory share a name; users pointing the source dir at an existing source file by mistake.","solutions":["Remove or rename the conflicting regular file at the reported path.","Point the output directory argument at a path that does not collide with an existing file.","Clear the output location between runs, or use a fresh output directory.","Pre-check with Files.isDirectory(Path) (and !Files.isRegularFile) before setting the arg."],"exampleFix":"// before\nargs.setOutDirSrc(new File(\"out/src\")); // a file named 'src' already exists under out/\n\n// after\nFile srcDir = new File(\"out/src\");\nif (srcDir.exists() && !srcDir.isDirectory()) {\n    throw new IllegalStateException(\"'src' exists as a file, refusing to overwrite: \" + srcDir);\n}\nargs.setOutDirSrc(srcDir);","handlingStrategy":"validation","validationCode":"private static File checkOutDir(File dir, String desc) {\n    if (dir != null && dir.exists() && !dir.isDirectory()) {\n        throw new IllegalStateException(desc + \" path is a file, not a directory: \" + dir);\n    }\n    return dir;\n}\ncheckOutDir(args.getOutDirSrc(), \"source out\");\ncheckOutDir(args.getOutDirRes(), \"resource out\");","typeGuard":null,"tryCatchPattern":"try {\n    decompiler.load();\n} catch (JadxArgsValidateException e) {\n    if (e.getMessage().contains(\"exists as file\")) {\n        // remove/rename the conflicting file, then retry\n        new File(conflictingPath).delete();\n        decompiler.load();\n    } else throw e;\n}","preventionTips":["Point output dirs at fresh, dedicated paths each run.","Pre-check that each output path is either absent or already a directory.","Avoid reusing a path that a prior run populated with regular files."],"tags":["validation","filesystem","args","configuration"],"backgroundTag":null,"analyzedSha":"e738a26571d02919f01df40de93bc9a44dee4e18","analyzedAt":"2026-08-14T00:10:24.238Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}