{"record":{"id":"0f1cc52f246be1e3","repo":"shwenzhang/AndResGuard","slug":"file-must-be-a-directory-dir","errorCode":null,"errorMessage":"file must be a directory: ${dir}","messagePattern":"file must be a directory: (.+?)","errorType":"exception","errorClass":"DirectoryException","httpStatus":null,"severity":"error","filePath":"AndResGuard-core/src/main/java/com/tencent/mm/directory/FileDirectory.java","lineNumber":36,"sourceCode":"import java.io.FileInputStream;\nimport java.io.FileNotFoundException;\nimport java.io.FileOutputStream;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.util.LinkedHashMap;\nimport java.util.LinkedHashSet;\n\npublic class FileDirectory extends AbstractDirectory {\n  private File mDir;\n\n  public FileDirectory(String dir) throws DirectoryException {\n    this(new File(dir));\n  }\n\n  public FileDirectory(File dir) throws DirectoryException {\n    super();\n    if (!dir.isDirectory()) {\n      throw new DirectoryException(\"file must be a directory: \" + dir);\n    }\n    mDir = dir;\n  }\n\n  @Override\n  protected AbstractDirectory createDirLocal(String name) throws DirectoryException {\n    File dir = new File(generatePath(name));\n    dir.mkdir();\n    return new FileDirectory(dir);\n  }\n\n  @Override\n  protected InputStream getFileInputLocal(String name) throws DirectoryException {\n    try {\n      return new FileInputStream(generatePath(name));\n    } catch (FileNotFoundException e) {\n      throw new DirectoryException(e);\n    }","sourceCodeStart":18,"sourceCodeEnd":54,"githubUrl":"https://github.com/shwenzhang/AndResGuard/blob/e4df245d82f27d9a2d0dd108260a3510cbaba849/AndResGuard-core/src/main/java/com/tencent/mm/directory/FileDirectory.java#L18-L54","documentation":"FileDirectory's constructor throws DirectoryException(\"file must be a directory: <path>\") when the given java.io.File exists but is not a directory (or the constructor is handed a file path instead of a folder path). The guard is dir.isDirectory().","triggerScenarios":"new FileDirectory(file) where `file` points at a regular file (e.g. an .apk or .zip) instead of a folder; also on a stale path that no longer isDirectory().","commonSituations":"Passing the APK file itself where the unpacked/output directory was expected; mixing up input-file vs output-dir config values in a build script.","solutions":["Pass the directory, not a file: verify target.isDirectory() before constructing FileDirectory.","If you have a file and need its containing directory, use file.getParentFile().","Create the directory first (mkdirs) when it may not exist yet."],"exampleFix":"// before\nAbstractDirectory dir = new FileDirectory(new File(\"app.apk\"));\n// after\nFile outDir = new File(\"build/resguard\");\nif (!outDir.isDirectory() && !outDir.mkdirs()) { throw new IOException(\"cannot create \" + outDir); }\nAbstractDirectory dir = new FileDirectory(outDir);","handlingStrategy":"validation","validationCode":"File f = new File(path); if (!f.isDirectory()) throw new IllegalArgumentException(\"not a directory: \" + f);","typeGuard":null,"tryCatchPattern":"try { new FileDirectory(f); } catch (DirectoryException e) { /* f is not a directory; fix path */ }","preventionTips":["Validate isDirectory() before constructing","Use getParentFile() when you actually hold a file handle","mkdirs() target output directories before use"],"tags":["file-system","constructor","validation"],"backgroundTag":"path-is-not-a-directory","analyzedSha":"e4df245d82f27d9a2d0dd108260a3510cbaba849","analyzedAt":"2026-09-12T17:49:07.798Z","contentChangedAt":"2026-09-12T17:49:07.798Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}