shwenzhang/AndResGuard · warning
UnsupportedOperationException
Error message
UnsupportedOperationException
What it means
ZipRODirectory is read-only; createDirLocal unconditionally throws UnsupportedOperationException. Any mutation path that reaches createDir on a ZipRODirectory (including createDir/getFileOutput in AbstractDirectory) fails because zip-backed trees cannot create new entries in place.
Solutions
- Extract the zip into a real folder (new FileDirectory(unpackedDir)) and perform all mutations there.
- Only use read APIs (getFileInput, containsFile, listEntries) on ZipRODirectory instances.
- Wrap createDir in try-catch UnsupportedOperationException if your code must handle both read-only and writable directories.
Example fix
// before
Directory dir = new ZipRODirectory(apkFile, "");
Directory out = dir.createDir("new/res"); // UnsupportedOperationException
// after
File unpacked = new File("build/apk-unpacked");
unpacked.mkdirs();
Directory dir = new FileDirectory(unpacked);
Directory out = dir.createDir("new/res"); Defensive patterns
Strategy: try-catch
Validate before calling
if (dir instanceof ZipRODirectory) { /* use read-only APIs or unpack to FileDirectory first */ } Type guard
boolean isWritableDirectory(AbstractDirectory d) { return d instanceof FileDirectory; } Try / catch
try { return dir.createDir(path); } catch (UnsupportedOperationException e) { return unpackAndCreate(dir, path); } Prevention
- Treat ZipRODirectory as strictly read-only in your code
- Unpack archives to a FileDirectory before any mutation
- Write tests covering both directory implementations if you support both
When it happens
Trigger: Calling createDir(path) or getFileOutput on a ZipRODirectory obtained from an APK/zip, e.g. trying to add new resource folders directly inside the archive.
Common situations: Attempting to write obfuscated resources back into the source APK; copying a write-flow built on FileDirectory to a zip-backed Directory without changing types.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
AI-assisted analysis of shwenzhang/AndResGuard@e4df245d82 (2026-09-12).
Data as JSON: /api/errors/cf80baf0b7589e73.
Report an issue: GitHub.
Appendix: source
Thrown at AndResGuard-core/src/main/java/com/tencent/mm/directory/ZipRODirectory.java:65
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 {
return getZipFile().getInputStream(new ZipEntry(getPath() + name));
} catch (IOException e) {
throw new PathNotExist(name, e);
}
}
@Override
protected OutputStream getFileOutputLocal(String name) throws DirectoryException {
throw new UnsupportedOperationException();
}
@Override
protected void loadDirs() {View on GitHub (pinned to e4df245d82)