{"record":{"id":"483444e1b6a43e4b","repo":"pxb1988/dex2jar","slug":"string-more-than-65535-utf-bytes-long","errorCode":null,"errorMessage":"String more than 65535 UTF bytes long","messagePattern":"String more than 65535 UTF bytes long","errorType":"exception","errorClass":"UTFDataFormatException","httpStatus":null,"severity":"error","filePath":"dex-reader/src/main/java/com/googlecode/d2j/util/Mutf8.java","lineNumber":80,"sourceCode":"    }\n\n    /**\n     * Returns the number of bytes the modified UTF8 representation of 's' would take.\n     */\n    private static long countBytes(String s, boolean shortLength) throws UTFDataFormatException {\n        long result = 0;\n        final int length = s.length();\n        for (int i = 0; i < length; ++i) {\n            char ch = s.charAt(i);\n            if (ch != 0 && ch <= 127) { // U+0000 uses two bytes.\n                ++result;\n            } else if (ch <= 2047) {\n                result += 2;\n            } else {\n                result += 3;\n            }\n            if (shortLength && result > 65535) {\n                throw new UTFDataFormatException(\"String more than 65535 UTF bytes long\");\n            }\n        }\n        return result;\n    }\n\n    /**\n     * Encodes the modified UTF-8 bytes corresponding to {@code s} into {@code dst}, starting at {@code offset}.\n     */\n    public static void encode(byte[] dst, int offset, String s) {\n        final int length = s.length();\n        for (int i = 0; i < length; i++) {\n            char ch = s.charAt(i);\n            if (ch != 0 && ch <= 127) { // U+0000 uses two bytes.\n                dst[offset++] = (byte) ch;\n            } else if (ch <= 2047) {\n                dst[offset++] = (byte) (0xc0 | (0x1f & (ch >> 6)));\n                dst[offset++] = (byte) (0x80 | (0x3f & ch));\n            } else {","sourceCodeStart":62,"sourceCodeEnd":98,"githubUrl":"https://github.com/pxb1988/dex2jar/blob/b5bda4fb4935ae8b3869b422454ae3b3896c7bc1/dex-reader/src/main/java/com/googlecode/d2j/util/Mutf8.java#L62-L98","documentation":"Thrown by Mutf8.countBytes (via utfCount) when the MUTF-8 encoding of a string exceeds 65535 bytes while shortLength is set. Modified UTF-8 uses an unsigned 16-bit length prefix, so longer strings cannot be encoded.","triggerScenarios":"Calling utfCount/encode on a string whose MUTF-8 representation is over 65535 bytes (e.g. ~21845 CJK characters at 3 bytes each).","commonSituations":"Writing very long method names, string constants, or concatenated identifiers into DEX/class files with the 16-bit length limit; long debug strings.","solutions":["Shorten the string before writing (truncate or hash long identifiers)","Split the string into multiple entries if the format allows","Pass shortLength=false if the surrounding format actually uses a larger length field"],"exampleFix":"// before\nif (Mutf8.utfCount(s, true) > 65535) { /* throws anyway when counting */ }\n// after\nbyte[] b = Mutf8.encode(s);\nif (b.length > 65535) {\n    s = s.substring(0, 20000) + \"...\" + Integer.toHexString(s.hashCode());\n}","handlingStrategy":"validation","validationCode":"if (Mutf8.utfCount(s, true) > 65535) { throw new IllegalArgumentException(\"string too long for MUTF-8 short form\"); }","typeGuard":"null","tryCatchPattern":"try { utfCount(s, true); } catch (UTFDataFormatException e) { s = truncate(s); }","preventionTips":["Check utfCount before writing any string into DEX/class formats","Cap identifier/string lengths at generation time (e.g. 65535 bytes)","Hash or truncate long strings instead of failing at write time"],"tags":["utf-8","length-limit","dex"],"backgroundTag":"value-out-of-range","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"}