{"record":{"id":"dcab9226bb09f49d","repo":"apache/shardingsphere","slug":"read-json-data-unexpected-exception","errorCode":null,"errorMessage":"Read json data unexpected exception","messagePattern":"Read json data unexpected exception","errorType":"exception","errorClass":"IngestException","httpStatus":null,"severity":"critical","filePath":"kernel/data-pipeline/dialect/postgresql/src/main/java/org/apache/shardingsphere/data/pipeline/postgresql/ingest/incremental/wal/decode/TestDecodingPlugin.java","lineNumber":246,"sourceCode":"    }\n    \n    private String readNextJson(final ByteBuffer data) {\n        data.get();\n        int offset = 0;\n        int startPosition = data.position();\n        int level = 0;\n        while (data.hasRemaining()) {\n            offset++;\n            char c = (char) data.get();\n            if ('{' == c) {\n                level++;\n            } else if ('}' == c) {\n                level--;\n                if (0 != level) {\n                    continue;\n                }\n                if ('\\'' != data.get()) {\n                    throw new IngestException(\"Read json data unexpected exception\");\n                }\n                if (data.hasRemaining()) {\n                    data.get();\n                }\n                return readStringSegment(data, startPosition, offset).replace(\"''\", \"'\");\n            }\n        }\n        return null;\n    }\n    \n    private String readStringSegment(final ByteBuffer data, final int startPosition, final int offset) {\n        byte[] result = new byte[offset];\n        for (int i = 0; i < offset; i++) {\n            result[i] = data.get(startPosition + i);\n        }\n        return new String(result, StandardCharsets.UTF_8);\n    }\n    ","sourceCodeStart":228,"sourceCodeEnd":264,"githubUrl":"https://github.com/apache/shardingsphere/blob/e952770a215630a3659c75d64369168cd3e26b82/kernel/data-pipeline/dialect/postgresql/src/main/java/org/apache/shardingsphere/data/pipeline/postgresql/ingest/incremental/wal/decode/TestDecodingPlugin.java#L228-L264","documentation":"Thrown while decoding a JSON value from test_decoding output: after matching the closing '}' of a balanced JSON object the parser expects a terminating single-quote. If the next byte is not a quote, the message framing is not what the decoder assumes, so it fails fast with an IngestException instead of returning corrupt data.","triggerScenarios":"An incremental event whose column value is a JSON/JSONB literal is decoded: the brace-matching loop exits at depth 0 and data.get() returns a character other than '\\''. Produced by test_decoding format changes, JSON values containing unusual quoting, or a slot whose output was created with options that alter quoting of composite values.","commonSituations":"Tables with json/jsonb columns replicated through test_decoding; PostgreSQL version differences in how test_decoding quotes composite/JSON values; partial reads caused by an earlier parse misalignment in the same buffer.","solutions":["Verify the PostgreSQL test_decoding version and slot options; recreate the slot with default options if custom options were used.","Check whether the failing table contains json/jsonb columns and whether the value shape (nested quotes, escaped quotes) trips the parser; capture the raw slot output with pg_logical_slot_peek_changes to confirm.","Upgrade ShardingSphere to a patch release containing test_decoding JSON parsing fixes.","As a workaround, exclude the affected table from the migration/CDC job or alter the column type, then restart the job."],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    value = plugin.readValue(data);\n} catch (final IngestException ex) {\n    log.error(\"JSON decode failed, dumping remaining buffer for diagnosis\", ex);\n    throw ex;\n}","preventionTips":["Test CDC on tables with json/jsonb columns in a staging environment before production.","Keep PostgreSQL minor versions consistent across replicas feeding the slot.","Keep ShardingSphere patched; JSON decode fixes land in point releases."],"tags":["postgresql","json","cdc","wal","parser"],"backgroundTag":null,"analyzedSha":"e952770a215630a3659c75d64369168cd3e26b82","analyzedAt":"2026-08-14T13:54:53.392Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}