{"record":{"id":"9714a3a97e18430a","repo":"apache/cassandra","slug":"invalid-ascii-character-in-string-literal-s","errorCode":null,"errorMessage":"Invalid ASCII character in string literal: %s","messagePattern":"Invalid ASCII character in string literal: (.+?)","errorType":"validation","errorClass":"MarshalException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/db/marshal/AsciiType.java","lineNumber":68,"sourceCode":"        protected CharsetEncoder initialValue()\n        {\n            return StandardCharsets.US_ASCII.newEncoder();\n        }\n    };\n\n    public ByteBuffer fromString(String source)\n    {\n        // the encoder must be reset each time it's used, hence the thread-local storage\n        CharsetEncoder theEncoder = encoder.get();\n        theEncoder.reset();\n\n        try\n        {\n            return theEncoder.encode(CharBuffer.wrap(source));\n        }\n        catch (CharacterCodingException exc)\n        {\n            throw new MarshalException(String.format(\"Invalid ASCII character in string literal: %s\", exc));\n        }\n    }\n\n    @Override\n    public Term fromJSONObject(Object parsed) throws MarshalException\n    {\n        try\n        {\n            return new Constants.Value(fromString((String) parsed));\n        }\n        catch (ClassCastException exc)\n        {\n            throw new MarshalException(String.format(\n                    \"Expected an ascii string, but got a %s: %s\", parsed.getClass().getSimpleName(), parsed));\n        }\n    }\n\n    @Override","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/db/marshal/AsciiType.java#L50-L86","documentation":"AsciiType.fromString throws this MarshalException when the input string cannot be encoded as US-ASCII (JVM CharacterCodingException during ASCII encoding). Cassandra's ascii comparator only accepts 7-bit ASCII characters, so any character outside 0x00-0x7F (e.g. UTF-8 multibyte characters) fails. The error surfaces through fromJSONObject when JSON values are validated as ascii columns.","triggerScenarios":"INSERT/UPDATE of an ascii-typed column or partition key containing non-ASCII characters (e.g. 'café', emoji); fromJSONObject called on a JSON string value for an ascii column containing non-ASCII bytes; CQL string literals with smart quotes or accented characters bound to ascii columns.","commonSituations":"Migrating data from UTF-8 systems into a legacy ascii column; copy-pasted text containing curly quotes/em-dashes; internationalized usernames inserted into ascii keys; cqlsh input with locale-dependent characters.","solutions":["Replace non-ASCII characters in the value with ASCII equivalents before insert","Use text (UTF-8) or blob type instead of ascii if the data legitimately needs non-ASCII","Use ALTER TABLE to change the column type from ascii to text (ascii is compatible with text)","Strip/normalize the input programmatically (e.g. Normalizer + remove diacritics) before binding"],"exampleFix":"// before\nINSERT INTO users (id, name) VALUES (1, 'café'); -- ascii column\n// after\nINSERT INTO users (id, name) VALUES (1, 'cafe'); -- or ALTER TABLE users ALTER name TYPE text;","handlingStrategy":"validation","validationCode":"public static void assertAscii(String s) {\n    if (s != null && !s.chars().allMatch(c -> c >= 0 && c <= 127))\n        throw new IllegalArgumentException(\"Non-ASCII char in: \" + s);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Prefer text over ascii for new schemas — ascii is a legacy type","Normalize/strip diacritics (java.text.Normalizer) before binding","Avoid copy-paste into ascii columns; lint payloads for non-ASCII","Test ascii-keyed paths with international sample data"],"tags":["cassandra","marshal","ascii","encoding"],"backgroundTag":"invalid-argument-format","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}