{"record":{"id":"1022d7c1afadcc43","repo":"pxb1988/dex2jar","slug":"bad-utf-8-byte-02x-at-offset-08x","errorCode":null,"errorMessage":"bad utf-8 byte %02x at offset %08x","messagePattern":"bad utf-8 byte %02x at offset %08x","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"dex-reader/src/main/java/com/googlecode/d2j/util/Utf8Utils.java","lineNumber":185,"sourceCode":"            outAt++;\n        }\n\n        return new String(chars, 0, outAt);\n    }\n\n    /**\n     * Helper for {@link #utf8BytesToString}, which throws the right exception for a bogus utf-8 byte.\n     * \n     * @param value\n     *            the byte value\n     * @param offset\n     *            the file offset\n     * @return never\n     * @throws IllegalArgumentException\n     *             always thrown\n     */\n    private static String throwBadUtf8(int value, int offset) {\n        throw new IllegalArgumentException(\"bad utf-8 byte \" + String.format(\"%02x\", value) + \" at offset \"\n                + String.format(\"%08x\", offset));\n    }\n\n    public static void writeEscapedChar(Writer writer, char c) throws IOException {\n        if ((c >= ' ') && (c < 0x7f)) {\n            if ((c == '\\'') || (c == '\\\"') || (c == '\\\\')) {\n                writer.write('\\\\');\n            }\n            writer.write(c);\n            return;\n        } else if (c <= 0x7f) {\n            switch (c) {\n            case '\\n':\n                writer.write(\"\\\\n\");\n                return;\n            case '\\r':\n                writer.write(\"\\\\r\");\n                return;","sourceCodeStart":167,"sourceCodeEnd":203,"githubUrl":"https://github.com/pxb1988/dex2jar/blob/b5bda4fb4935ae8b3869b422454ae3b3896c7bc1/dex-reader/src/main/java/com/googlecode/d2j/util/Utf8Utils.java#L167-L203","documentation":"Thrown by Utf8Utils.throwBadUtf8 (from utf8BytesToString) when a byte at a given offset is not a valid MUTF-8 lead or continuation byte. IllegalArgumentException naming the bad byte value in hex and its offset in the byte array.","triggerScenarios":"Calling Utf8Utils.utf8BytesToString on bytes containing invalid MUTF-8 sequences — bad lead bytes (>= 0xF0 or 0x80-0xBF as lead) or non-continuation trailing bytes.","commonSituations":"Reading strings from corrupted DEX files, decoding raw UTF-16 or Latin-1 bytes as MUTF-8, wrong offsets into string data.","solutions":["Validate/repair the input bytes before conversion, or decode defensively with a try-catch for IllegalArgumentException","Check the byte offset passed to utf8BytesToString points at the actual string start","Re-obtain or rebuild the DEX file if corruption is confirmed"],"exampleFix":"// before\nString s = Utf8Utils.utf8BytesToString(bytes, offset, length);\n// after\nString s;\ntry {\n    s = Utf8Utils.utf8BytesToString(bytes, offset, length);\n} catch (IllegalArgumentException e) {\n    s = new String(bytes, offset, length, StandardCharsets.ISO_8859_1); // lossy fallback\n}","handlingStrategy":"try-catch","validationCode":"try { Utf8Utils.utf8BytesToString(bytes, off, len); } catch (IllegalArgumentException e) { /* invalid */ }","typeGuard":"null","tryCatchPattern":"try { s = Utf8Utils.utf8BytesToString(bytes, off, len); } catch (IllegalArgumentException e) { s = lossyDecode(bytes, off, len); }","preventionTips":["Confirm offsets point at the true string start within the byte array","Validate DEX file checksum before string extraction","Use a lossy fallback decode for diagnostics instead of aborting the whole conversion"],"tags":["utf-8","dex","decoding","corrupt-input"],"backgroundTag":"invalid-argument-format","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"}