{"record":{"id":"a9383d83df36af3c","repo":"shwenzhang/AndResGuard","slug":"directoryexception-ziprodirectory","errorCode":null,"errorMessage":"DirectoryException","messagePattern":"DirectoryException","errorType":"exception","errorClass":"DirectoryException","httpStatus":null,"severity":"error","filePath":"AndResGuard-core/src/main/java/com/tencent/mm/directory/ZipRODirectory.java","lineNumber":52,"sourceCode":"\n  public ZipRODirectory(File zipFile) throws DirectoryException {\n    this(zipFile, \"\");\n  }\n\n  public ZipRODirectory(ZipFile zipFile) {\n    this(zipFile, \"\");\n  }\n\n  public ZipRODirectory(String zipFileName, String path) throws DirectoryException {\n    this(new File(zipFileName), path);\n  }\n\n  public ZipRODirectory(File zipFile, String path) throws DirectoryException {\n    super();\n    try {\n      mZipFile = new ZipFile(zipFile);\n    } catch (IOException e) {\n      throw new DirectoryException(e);\n    }\n    mPath = path;\n  }\n\n  public ZipRODirectory(ZipFile zipFile, String path) {\n    super();\n    mZipFile = zipFile;\n    mPath = path;\n  }\n\n  @Override\n  protected AbstractDirectory createDirLocal(String name) throws DirectoryException {\n    throw new UnsupportedOperationException();\n  }\n\n  @Override\n  protected InputStream getFileInputLocal(String name) throws DirectoryException {\n    try {","sourceCodeStart":34,"sourceCodeEnd":70,"githubUrl":"https://github.com/shwenzhang/AndResGuard/blob/e4df245d82f27d9a2d0dd108260a3510cbaba849/AndResGuard-core/src/main/java/com/tencent/mm/directory/ZipRODirectory.java#L34-L70","documentation":"ZipRODirectory's constructor throws DirectoryException when new ZipFile(zipFile) fails with an IOException, i.e. the zip cannot be opened because it is missing, unreadable, or not a valid zip archive.","triggerScenarios":"new ZipRODirectory(File, String) with a file that does not exist, is locked/corrupt, or is not a real zip (e.g. an encrypted or partially downloaded APK).","commonSituations":"Pointing the tool at an unsigned/corrupted intermediate APK; a previous build step truncated the file; passing an AAB or non-zip artifact.","solutions":["Verify the zip exists and is readable before constructing: file.exists() && file.canRead().","Validate the archive is a real zip (e.g. ZipFile-open a probe or check magic bytes PK\\\\x03\\\\x04) and re-acquire/rebuild the artifact if corrupt.","Catch DirectoryException and surface the cause IOException to the user."],"exampleFix":"// before\nDirectory dir = new ZipRODirectory(apkFile, \"res\");\n// after\nif (!apkFile.isFile() || !apkFile.canRead()) throw new IOException(\"apk missing: \" + apkFile);\ntry {\n  Directory dir = new ZipRODirectory(apkFile, \"res\");\n} catch (DirectoryException e) {\n  throw new IOException(\"invalid zip apk: \" + apkFile, e.getCause());\n}","handlingStrategy":"try-catch","validationCode":"if (!zipFile.isFile() || !zipFile.canRead()) throw new IOException(\"zip missing/unreadable: \" + zipFile);","typeGuard":null,"tryCatchPattern":"try { Directory d = new ZipRODirectory(zipFile, path); } catch (DirectoryException e) { throw new IOException(\"invalid or unreadable zip: \" + zipFile, e.getCause()); }","preventionTips":["Verify artifact integrity (exists, non-zero size, readable) before opening","Rebuild/re-download corrupted artifacts instead of retrying the open","Confirm the input is actually a zip (APK), not an AAB or encrypted file"],"tags":["zip","io","wrapped-exception"],"backgroundTag":"file-open-failed","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"}