apache/shardingsphere · critical · IngestException

Read json data unexpected exception

Error message

Read json data unexpected exception

What it means

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.

Source

Thrown at kernel/data-pipeline/dialect/postgresql/src/main/java/org/apache/shardingsphere/data/pipeline/postgresql/ingest/incremental/wal/decode/TestDecodingPlugin.java:246

    }
    
    private String readNextJson(final ByteBuffer data) {
        data.get();
        int offset = 0;
        int startPosition = data.position();
        int level = 0;
        while (data.hasRemaining()) {
            offset++;
            char c = (char) data.get();
            if ('{' == c) {
                level++;
            } else if ('}' == c) {
                level--;
                if (0 != level) {
                    continue;
                }
                if ('\'' != data.get()) {
                    throw new IngestException("Read json data unexpected exception");
                }
                if (data.hasRemaining()) {
                    data.get();
                }
                return readStringSegment(data, startPosition, offset).replace("''", "'");
            }
        }
        return null;
    }
    
    private String readStringSegment(final ByteBuffer data, final int startPosition, final int offset) {
        byte[] result = new byte[offset];
        for (int i = 0; i < offset; i++) {
            result[i] = data.get(startPosition + i);
        }
        return new String(result, StandardCharsets.UTF_8);
    }
    

View on GitHub (pinned to e952770a21)

Solutions

  1. Verify the PostgreSQL test_decoding version and slot options; recreate the slot with default options if custom options were used.
  2. 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.
  3. Upgrade ShardingSphere to a patch release containing test_decoding JSON parsing fixes.
  4. As a workaround, exclude the affected table from the migration/CDC job or alter the column type, then restart the job.
Defensive patterns

Strategy: fallback

Try / catch

try {
    value = plugin.readValue(data);
} catch (final IngestException ex) {
    log.error("JSON decode failed, dumping remaining buffer for diagnosis", ex);
    throw ex;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of apache/shardingsphere@e952770a21 (2026-08-14). Data as JSON: /api/errors/dcab9226bb09f49d. Report an issue: GitHub.