{"record":{"id":"b92f0716913e38d0","repo":"apache/cassandra","slug":"string-didn-t-validate","errorCode":null,"errorMessage":"String didn't validate.","messagePattern":"String didn't validate\\.","errorType":"validation","errorClass":"MarshalException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/serializers/UTF8Serializer.java","lineNumber":39,"sourceCode":"import java.nio.charset.StandardCharsets;\n\nimport org.apache.cassandra.db.marshal.ByteArrayAccessor;\nimport org.apache.cassandra.db.marshal.ByteBufferAccessor;\nimport org.apache.cassandra.db.marshal.ValueAccessor;\n\npublic class UTF8Serializer extends AbstractTextSerializer\n{\n    public static final UTF8Serializer instance = new UTF8Serializer();\n\n    protected UTF8Serializer()\n    {\n        super(StandardCharsets.UTF_8);\n    }\n\n    public <V> void validate(V value, ValueAccessor<V> accessor) throws MarshalException\n    {\n        if (!UTF8Validator.validate(value, accessor))\n            throw new MarshalException(\"String didn't validate.\");\n    }\n\n    static class UTF8Validator\n    {\n        enum State\n        {\n            START,\n            TWO,\n            TWO_80,\n            THREE_a0bf,\n            THREE_80bf_1,\n            THREE_80bf_2,\n            FOUR_90bf,\n            FOUR_80bf_3,\n        };\n\n        // since we're not converting to java strings, we don't need to worry about converting to surrogates.\n        // buf has already been sliced/duplicated.","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/serializers/UTF8Serializer.java#L21-L57","documentation":"MarshalException from UTF8Serializer.validate when UTF8Validator fails on the byte sequence: the bytes are not valid UTF-8 (illegal lead/trail bytes, overlong encodings, or truncated multi-byte sequences). Sentinels note the message carries no detail on purpose; the actual byte offsets are not reported.","triggerScenarios":"Thrown at src/java/org/apache/cassandra/serializers/UTF8Serializer.java:39 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Ensure the client encodes strings as UTF-8 (check character-set settings, avoid latin-1 or UTF-16 serialization)","Sanitize input data before insert; use a text column with correct driver encoding","If data arrived corrupted in transit, verify network/proxy layer is not re-encoding bytes"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}