{"record":{"id":"c349cec74a1049fb","repo":"alibaba/canal","slug":"illegal-json-data","errorCode":null,"errorMessage":"illegal json data","messagePattern":"illegal json data","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"dbsync/src/main/java/com/taobao/tddl/dbsync/binlog/JsonConversion.java","lineNumber":82,"sourceCode":"        switch (type) {\n            case JSONB_TYPE_SMALL_OBJECT:\n                return parse_array_or_object(Json_enum_type.OBJECT, buffer, len, false, charset);\n            case JSONB_TYPE_LARGE_OBJECT:\n                return parse_array_or_object(Json_enum_type.OBJECT, buffer, len, true, charset);\n            case JSONB_TYPE_SMALL_ARRAY:\n                return parse_array_or_object(Json_enum_type.ARRAY, buffer, len, false, charset);\n            case JSONB_TYPE_LARGE_ARRAY:\n                return parse_array_or_object(Json_enum_type.ARRAY, buffer, len, true, charset);\n            default:\n                return parse_scalar(type, buffer, len, charset);\n        }\n    }\n\n    private static Json_Value parse_array_or_object(Json_enum_type type, LogBuffer buffer, long len, boolean large,\n                                                    Charset charset) {\n        long offset_size = large ? LARGE_OFFSET_SIZE : SMALL_OFFSET_SIZE;\n        if (len < 2 * offset_size) {\n            throw new IllegalArgumentException(\"illegal json data\");\n        }\n        long element_count = read_offset_or_size(buffer, large);\n        long bytes = read_offset_or_size(buffer, large);\n\n        if (bytes > len) {\n            throw new IllegalArgumentException(\"illegal json data\");\n        }\n        long header_size = 2 * offset_size;\n        if (type == Json_enum_type.OBJECT) {\n            header_size += element_count * (large ? KEY_ENTRY_SIZE_LARGE : KEY_ENTRY_SIZE_SMALL);\n        }\n\n        header_size += element_count * (large ? VALUE_ENTRY_SIZE_LARGE : VALUE_ENTRY_SIZE_SMALL);\n        if (header_size > bytes) {\n            throw new IllegalArgumentException(\"illegal json data\");\n        }\n        return new Json_Value(type, buffer.rewind(), element_count, bytes, large);\n    }","sourceCodeStart":64,"sourceCodeEnd":100,"githubUrl":"https://github.com/alibaba/canal/blob/87be50e87686a3e8af08c368d0e1ffd1f59eb04a/dbsync/src/main/java/com/taobao/tddl/dbsync/binlog/JsonConversion.java#L64-L100","documentation":"Thrown by JsonConversion.parse_array_or_object() when the supplied JSONB value length is smaller than twice the offset size (4 bytes for small, 8 for large). A MySQL binary JSON array/object must carry at least an element-count and a total-size entry; a value shorter than that cannot be valid, so the parser rejects it as illegal json data.","triggerScenarios":"While decoding a binlog JSON column, the binary value passed to parse_array_or_object has len < 2*offset_size - either the length was misread from the event, the buffer was truncated, or the value is not actually JSON.","commonSituations":"Truncated/corrupt binlog row event; a length field read with the wrong endianness/size upstream; a MySQL version emitting a JSON binary format revision this parser does not recognize; partial event after a network drop.","solutions":["Re-stream the binlog from a known-good position to rule out transient truncation.","Verify the event is genuinely a JSON column (JSONB_TYPE_OBJECT/ARRAY marker) and not a misread type byte.","Confirm the MySQL server version's binary JSON format matches what this JsonConversion supports.","Validate the row event's column-count and length preamble upstream so parse_array_or_object receives correct bounds."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Sanity-check JSONB length before descending into parse_array_or_object\nif (len < (large ? 8L : 4L)) {\n    logger.warn(\"JSON value too short for header (len=\" + len + \")\");\n    return null; // or throw a domain exception\n}","typeGuard":null,"tryCatchPattern":"try { Json_Value v = JsonConversion.parse_value(type, buf, len, charset); }\ncatch (IllegalArgumentException e) {\n    if (e.getMessage().equals(\"illegal json data\"))\n        logger.warn(\"skipping malformed JSONB value in binlog\", e);\n}","preventionTips":["Validate event/length preamble before parsing JSON.","Re-stream from a known-good binlog position on JSONB parse failures.","Confirm MySQL server version JSONB compatibility."],"tags":["binlog","json","decoding","corruption","mysql"],"backgroundTag":null,"analyzedSha":"87be50e87686a3e8af08c368d0e1ffd1f59eb04a","analyzedAt":"2026-08-14T04:30:11.918Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}