{"record":{"id":"42cc37e25c709692","repo":"apache/shardingsphere","slug":"underlying-sql-state-s-underlying-error-code-42cc37","errorCode":null,"errorMessage":"Underlying SQL state: %s, underlying error code: %s.","messagePattern":"Underlying SQL state: (.+?), underlying error code: (.+?)\\.","errorType":"exception","errorClass":"SQLWrapperException","httpStatus":null,"severity":"error","filePath":"database/protocol/dialect/postgresql/src/main/java/org/apache/shardingsphere/database/protocol/postgresql/packet/command/query/extended/bind/protocol/text/impl/PostgreSQLJsonValueParser.java","lineNumber":39,"sourceCode":"import org.apache.shardingsphere.infra.exception.external.sql.type.wrapper.SQLWrapperException;\nimport org.postgresql.util.PGobject;\n\nimport java.sql.SQLException;\n\n/**\n * Json value parser of PostgreSQL.\n */\npublic final class PostgreSQLJsonValueParser implements PostgreSQLTextValueParser<PGobject> {\n    \n    @Override\n    public PGobject parse(final String value) {\n        try {\n            PGobject result = new PGobject();\n            result.setType(\"json\");\n            result.setValue(value);\n            return result;\n        } catch (final SQLException ex) {\n            throw new SQLWrapperException(ex);\n        }\n    }\n}\n","sourceCodeStart":21,"sourceCodeEnd":43,"githubUrl":"https://github.com/apache/shardingsphere/blob/e952770a215630a3659c75d64369168cd3e26b82/database/protocol/dialect/postgresql/src/main/java/org/apache/shardingsphere/database/protocol/postgresql/packet/command/query/extended/bind/protocol/text/impl/PostgreSQLJsonValueParser.java#L21-L43","documentation":"PostgreSQLJsonValueParser.parse builds a PGobject typed 'json'; any SQLException from PGobject.setValue is wrapped in SQLWrapperException ('Underlying SQL state / error code' message). It triggers when a text bind parameter for a json column fails PGobject's json validation.","triggerScenarios":"Binding a parameter declared as json with a string that PGobject rejects, e.g. '{invalid json', truncated payloads, or a null/empty string passed where a json document is required, during extended-protocol bind.","commonSituations":"Payload truncation over the wire, encoding issues (invalid UTF-8 sequences), or applications inserting user-supplied strings without validating JSON first.","solutions":["Validate the payload parses as JSON before binding (use a JSON library on the client)","Use a JSON/JSONB-typed client type (e.g. PGobject with type json, or driver's Json support) instead of a raw string","Check the wrapped SQLException state/code for the precise validation failure","Guard against null/empty payloads with explicit NULL binding if the column allows it"],"exampleFix":"// before\nstmt.setString(1, \"{oops\");\n// after\nnew com.google.gson.JsonParser().parseString(jsonText); // throws early client-side\nstmt.setString(1, jsonText);","handlingStrategy":"validation","validationCode":"try { new org.json.JSONTokener(jsonText).nextValue(); return true; } catch (org.json.JSONException e) { return false; }","typeGuard":null,"tryCatchPattern":"catch (SQLWrapperException e) { /* cause is SQLException from PGobject; surface to user as invalid JSON payload */ }","preventionTips":["Validate JSON with a real parser before binding","Never concatenate unvalidated user input into json parameters","Handle empty payloads explicitly (bind NULL if column allows)"],"tags":["postgresql","bind","json","value-parsing"],"backgroundTag":null,"analyzedSha":"e952770a215630a3659c75d64369168cd3e26b82","analyzedAt":"2026-08-14T13:54:53.392Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}