{"record":{"id":"75100608ad475d0a","repo":"pxb1988/dex2jar","slug":"the-src-file-not-a-dex-or-zip-file","errorCode":null,"errorMessage":"the src file not a .dex or zip file","messagePattern":"the src file not a \\.dex or zip file","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"dex-reader/src/main/java/com/googlecode/d2j/reader/zip/ZipUtil.java","lineNumber":89,"sourceCode":"     * @throws IOException\n     */\n    public static byte[] readDex(byte[] data) throws IOException {\n        if (data.length < 3) {\n            throw new IOException(\"File too small to be a dex/zip\");\n        }\n        if (\"dex\".equals(new String(data, 0, 3, StandardCharsets.ISO_8859_1))) {// dex\n            return data;\n        } else if (\"PK\".equals(new String(data, 0, 2, StandardCharsets.ISO_8859_1))) {// ZIP\n            try (ZipFile zipFile = new ZipFile(data)) {\n                ZipEntry classes = zipFile.findFirstEntry(\"classes.dex\");\n                if (classes != null) {\n                    return toByteArray(zipFile.getInputStream(classes));\n                } else {\n                    throw new IOException(\"Can not find classes.dex in zip file\");\n                }\n            }\n        }\n        throw new IOException(\"the src file not a .dex or zip file\");\n    }\n}\n","sourceCodeStart":71,"sourceCodeEnd":92,"githubUrl":"https://github.com/pxb1988/dex2jar/blob/b5bda4fb4935ae8b3869b422454ae3b3896c7bc1/dex-reader/src/main/java/com/googlecode/d2j/reader/zip/ZipUtil.java#L71-L92","documentation":"ZipUtil.readDex(byte[]) throws IOException as its final fallback when the input bytes match neither the 'dex' magic nor the 'PK' zip prefix, so there is no supported way to obtain classes.dex from the data. Only raw dex bytes and zip containers are accepted.","triggerScenarios":"Calling ZipUtil.readDex on data whose first bytes are not 'dex' or 'PK' — ELF shared libraries, gzip streams, XML resources, HTML error pages from failed downloads.","commonSituations":"Passing an .odex/.vdex or lib*.so file where a dex was intended; a gzip-compressed dex not decompressed first; a download that saved an HTML error page instead of the APK.","solutions":["Verify the file type with magic bytes (file command) before calling readDex.","Decompress if the content is gzip/deflate, then retry.","Fix the download path if you received HTML/text instead of a binary artifact.","For non-dex binaries (.so/.odex/.vdex), use an appropriate converter first or pass real dex bytes."],"exampleFix":"// before\nbyte[] dex = ZipUtil.readDex(mysteryBytes);\n// after\nString magic = new String(mysteryBytes, 0, 3, StandardCharsets.ISO_8859_1);\nif (!magic.startsWith(\"dex\") && !magic.startsWith(\"PK\")) {\n    throw new IllegalArgumentException(\"not a dex/zip: magic=\" + magic);\n}\nbyte[] dex = ZipUtil.readDex(mysteryBytes);","handlingStrategy":"validation","validationCode":"String magic = data.length >= 3 ? new String(data, 0, 3, StandardCharsets.ISO_8859_1) : \"\";\nif (!magic.startsWith(\"dex\") && !magic.startsWith(\"PK\")) {\n    throw new IllegalArgumentException(\"readDex requires dex/zip, got magic=\" + magic);\n}","typeGuard":"static boolean isDexOrZip(byte[] d) {\n    return d != null && d.length >= 3 &&\n        (new String(d, 0, 3, StandardCharsets.ISO_8859_1).startsWith(\"dex\") ||\n         new String(d, 0, 2, StandardCharsets.ISO_8859_1).equals(\"PK\"));\n}","tryCatchPattern":"try {\n    byte[] dex = ZipUtil.readDex(data);\n} catch (IOException e) {\n    LOG.error(\"unsupported input format: \" + e.getMessage());\n}","preventionTips":["Check magic bytes before invoking dex tooling","Validate downloads (status code, content-type, size) before processing","Decompress compressed artifacts before calling readDex","Route .so/.odex/.vdex files to converters, not the dex reader"],"tags":["dex","android","zip","file-format"],"backgroundTag":"incompatible-source-type","analyzedSha":"b5bda4fb4935ae8b3869b422454ae3b3896c7bc1","analyzedAt":"2026-09-08T00:44:01.258Z","contentChangedAt":"2026-09-08T00:44:01.258Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}