shwenzhang/AndResGuard · error · DirectoryException

DirectoryException

Error message

DirectoryException

What it means

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.

Solutions

  1. Verify the zip exists and is readable before constructing: file.exists() && file.canRead().
  2. 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.
  3. Catch DirectoryException and surface the cause IOException to the user.

Example fix

// before
Directory dir = new ZipRODirectory(apkFile, "res");
// after
if (!apkFile.isFile() || !apkFile.canRead()) throw new IOException("apk missing: " + apkFile);
try {
  Directory dir = new ZipRODirectory(apkFile, "res");
} catch (DirectoryException e) {
  throw new IOException("invalid zip apk: " + apkFile, e.getCause());
}
Defensive patterns

Strategy: try-catch

Validate before calling

if (!zipFile.isFile() || !zipFile.canRead()) throw new IOException("zip missing/unreadable: " + zipFile);

Try / catch

try { Directory d = new ZipRODirectory(zipFile, path); } catch (DirectoryException e) { throw new IOException("invalid or unreadable zip: " + zipFile, e.getCause()); }

Prevention

When it happens

Trigger: 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).

Common situations: Pointing the tool at an unsigned/corrupted intermediate APK; a previous build step truncated the file; passing an AAB or non-zip artifact.

Understand the failure class

Background: "open() failed", "failed to open file", "cannot create file" — what a file open error means and how to fix it — this error's family across 42 libraries.

Related errors


AI-assisted analysis of shwenzhang/AndResGuard@e4df245d82 (2026-09-12). Data as JSON: /api/errors/a9383d83df36af3c. Report an issue: GitHub.

Appendix: source

Thrown at AndResGuard-core/src/main/java/com/tencent/mm/directory/ZipRODirectory.java:52

  public ZipRODirectory(File zipFile) throws DirectoryException {
    this(zipFile, "");
  }

  public ZipRODirectory(ZipFile zipFile) {
    this(zipFile, "");
  }

  public ZipRODirectory(String zipFileName, String path) throws DirectoryException {
    this(new File(zipFileName), path);
  }

  public ZipRODirectory(File zipFile, String path) throws DirectoryException {
    super();
    try {
      mZipFile = new ZipFile(zipFile);
    } catch (IOException e) {
      throw new DirectoryException(e);
    }
    mPath = path;
  }

  public ZipRODirectory(ZipFile zipFile, String path) {
    super();
    mZipFile = zipFile;
    mPath = path;
  }

  @Override
  protected AbstractDirectory createDirLocal(String name) throws DirectoryException {
    throw new UnsupportedOperationException();
  }

  @Override
  protected InputStream getFileInputLocal(String name) throws DirectoryException {
    try {

View on GitHub (pinned to e4df245d82)