{"record":{"id":"284821497bfa3a71","repo":"MuntashirAkon/AppManager","slug":"inputstream-is-not-a-dex-odex-file","errorCode":null,"errorMessage":"InputStream is not a dex, odex file.","messagePattern":"InputStream is not a dex, odex file\\.","errorType":"exception","errorClass":"DexFileFactory.UnsupportedFileTypeException","httpStatus":null,"severity":"error","filePath":"app/src/main/java/io/github/muntashirakon/AppManager/dex/DexUtils.java","lineNumber":229,"sourceCode":"            javaClass.decompile();\n            return javaClass.getCode();\n        }\n    }\n\n    @NonNull\n    public static DexBackedDexFile loadDexContainer(@NonNull InputStream inputStream, int api) throws IOException {\n        Opcodes opcodes = api < 0 ? Opcodes.getDefault() : Opcodes.forApi(api);\n        try {\n            return DexBackedDexFile.fromInputStream(opcodes, inputStream);\n        } catch (DexBackedDexFile.NotADexFile ex) {\n            // just eat it\n        }\n        try {\n            return DexBackedOdexFile.fromInputStream(opcodes, inputStream);\n        } catch (DexBackedOdexFile.NotAnOdexFile ex) {\n            // just eat it\n        }\n        throw new DexFileFactory.UnsupportedFileTypeException(\"InputStream is not a dex, odex file.\");\n    }\n}\n","sourceCodeStart":211,"sourceCodeEnd":232,"githubUrl":"https://github.com/MuntashirAkon/AppManager/blob/0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5/app/src/main/java/io/github/muntashirakon/AppManager/dex/DexUtils.java#L211-L232","documentation":"DexUtils.loadDexContainer() sniffs the input stream by attempting DexBackedDexFile and then DexBackedOdexFile parsing; when both reject the data it throws DexFileFactory.UnsupportedFileTypeException with this message. It means the stream is neither a standard DEX nor an ODEX file, so no dex container can be produced from it.","triggerScenarios":"Passing an InputStream to DexUtils.loadDexContainer() whose bytes are not DEX (magic \"dex\\n\") or ODEX (magic \"dey\\n\") — e.g. a ZIP/APK, a VDEX/CDex artifact, a text file, or a truncated/corrupted dex.","commonSituations":"Extracting the wrong entry from an APK (resources.arsc instead of classes.dex); passing a .vdex file from newer Android art; passing the APK itself instead of the inner dex; downloading a dex that was truncated or HTML-error-paged.","solutions":["Verify the stream starts with the DEX magic bytes 0x64 0x65 0x78 0x0A (\"dex\\n\") or ODEX magic \"dey\\n\" before calling loadDexContainer","If the input is an APK/JAR/ZIP, extract the classes*.dex entries first and feed those streams","If the input is VDEX/CDex (newer ART formats), convert it back to dex with external tools — this library does not parse them","Re-obtain the file and check its integrity (size/hash) in case of truncation or corruption"],"exampleFix":"// before\nDexContainer container = DexUtils.loadDexContainer(stream, opcodes);\n// after\nbyte[] header = new byte[4];\ntry (DataInputStream in = new DataInputStream(stream)) {\n    in.readFully(header);\n    if (!(new String(header, \"ISO_8859_1\").startsWith(\"dex\\n\"))) {\n        throw new IllegalArgumentException(\"Not a DEX file (bad magic)\");\n    }\n}\nDexContainer container = DexUtils.loadDexContainer(new ByteArrayInputStream(header), opcodes);","handlingStrategy":"try-catch","validationCode":"byte[] magic = new byte[4]; int n = stream.read(magic); if (n < 4 || !(new String(magic, 0, 4, StandardCharsets.ISO_8859_1).startsWith(\"dex\\n\") || new String(magic, 0, 4, StandardCharsets.ISO_8859_1).startsWith(\"dey\\n\"))) throw new IllegalArgumentException(\"Not a dex/odex stream\");","typeGuard":"boolean looksLikeDex(byte[] b) { return b != null && b.length > 7 && b[0]=='d' && b[1]=='e' && b[2]=='x' && b[3]=='\\n'; }","tryCatchPattern":"try { DexContainer c = DexUtils.loadDexContainer(stream, opcodes); } catch (DexFileFactory.UnsupportedFileTypeException e) { /* fall back to zip extraction of classes*.dex or inform user the file is unsupported */ }","preventionTips":["Always extract classes*.dex from APK/ZIP archives before parsing","Check file magic bytes before feeding streams to dex parsers","Reject VDEX/CDEX artifacts explicitly with a clear message","Verify download integrity (size/hash) to avoid truncated dex files"],"tags":["android","dex","file-format","input-validation"],"backgroundTag":"incompatible-source-type","analyzedSha":"0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5","analyzedAt":"2026-09-12T14:03:37.243Z","contentChangedAt":"2026-09-12T14:03:37.243Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}