{"record":{"id":"ae9e57c85e9d733a","repo":"skylot/jadx","slug":"failed-to-open-zip","errorCode":null,"errorMessage":"Failed to open zip: {}","messagePattern":"Failed to open zip: (.+?)","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"jadx-commons/jadx-zip/src/main/java/jadx/zip/ZipReader.java","lineNumber":55,"sourceCode":"\n\tpublic ZipReader(ZipReaderOptions options) {\n\t\tthis.options = options;\n\t}\n\n\t@SuppressWarnings(\"resource\")\n\tpublic ZipContent open(File zipFile) throws IOException {\n\t\tif (!zipFile.exists()) {\n\t\t\tthrow new FileNotFoundException(zipFile.getAbsolutePath());\n\t\t}\n\t\ttry {\n\t\t\tJadxZipParser jadxParser = new JadxZipParser(zipFile, options);\n\t\t\tIZipParser detectedParser = detectParser(zipFile, jadxParser);\n\t\t\treturn detectedParser.open();\n\t\t} catch (FallbackException e) {\n\t\t\tthrow e;\n\t\t} catch (Exception e) {\n\t\t\tif (options.getFlags().contains(ZipReaderFlags.DONT_USE_FALLBACK)) {\n\t\t\t\tthrow new IOException(\"Failed to open zip: \" + zipFile, e);\n\t\t\t}\n\t\t\t// switch to fallback parser\n\t\t\treturn buildFallbackParser(zipFile).open();\n\t\t}\n\t}\n\n\t/**\n\t * Visit valid entries in a zip file.\n\t * Return not null value from visitor to stop iteration.\n\t */\n\tpublic <R> @Nullable R visitEntries(File file, Function<IZipEntry, R> visitor) {\n\t\ttry (ZipContent content = open(file)) {\n\t\t\tfor (IZipEntry entry : content.getEntries()) {\n\t\t\t\tR result = visitor.apply(entry);\n\t\t\t\tif (result != null) {\n\t\t\t\t\treturn result;\n\t\t\t\t}\n\t\t\t}","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/skylot/jadx/blob/e738a26571d02919f01df40de93bc9a44dee4e18/jadx-commons/jadx-zip/src/main/java/jadx/zip/ZipReader.java#L37-L73","documentation":"Thrown by ZipReader.open inside the generic catch block: when an exception (other than FallbackException) occurs AND the options contain ZipReaderFlags.DONT_USE_FALLBACK, jadx rethrows as IOException with message 'Failed to open zip: <file>' chaining the original cause. Without that flag jadx would instead silently switch to the fallback parser.","triggerScenarios":"Opening a zip/apk that the primary JadxZipParser cannot parse (corrupt, unusual format, unsupported compression), while the caller has requested DONT_USE_FALLBACK so the fallback parser is bypassed.","commonSituations":"Corrupted or truncated APK/JAR; intentionally malformed test input; zip using features the jadx parser rejects; caller explicitly disabled fallback for strict validation.","solutions":["If fallback is acceptable, do NOT set ZipReaderFlags.DONT_USE_FALLBACK so jadx can retry with the fallback parser.","Verify the input is a valid zip (unzip -t or a zip integrity check).","Re-download or rebuild the archive if corrupt.","Inspect the chained cause for the specific parse failure."],"exampleFix":"// before\nZipReaderOptions opts = new ZipReaderOptions(security,\n    ZipReaderFlags.of(ZipReaderFlags.DONT_USE_FALLBACK));\nnew ZipReader(opts).open(file);\n// after\nZipReaderOptions opts = new ZipReaderOptions(security, ZipReaderFlags.none());\nnew ZipReader(opts).open(file);","handlingStrategy":"fallback","validationCode":"// Decide upfront whether fallback is acceptable for your use case\nboolean strict = mustValidateOnly();\nZipReaderFlags flags = strict ? ZipReaderFlags.of(ZipReaderFlags.DONT_USE_FALLBACK) : ZipReaderFlags.none();\nZipReader reader = new ZipReader(new ZipReaderOptions(security, flags));","typeGuard":"public static boolean canOpenWithoutFallback(ZipReader r, File f) {\n    try { r.open(f); return true; } catch (IOException e) { return false; }\n}","tryCatchPattern":"try {\n    reader.open(file);\n} catch (IOException e) {\n    if (e.getMessage().startsWith(\"Failed to open zip\")) {\n        // retry with fallback enabled\n        ZipReaderOptions relaxed = new ZipReaderOptions(security, ZipReaderFlags.none());\n        new ZipReader(relaxed).open(file);\n    } else throw e;\n}","preventionTips":["Do not set DONT_USE_FALLBACK unless you require strict validation.","Verify zip integrity (unzip -t) before strict parsing.","Log the chained cause to diagnose the primary parser failure."],"tags":["zip","io","fallback","jadx"],"backgroundTag":null,"analyzedSha":"e738a26571d02919f01df40de93bc9a44dee4e18","analyzedAt":"2026-08-14T00:10:24.238Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}