{"record":{"id":"ca4e61c62f4f98d3","repo":"apache/cassandra","slug":"unable-to-make-uuid-from-s","errorCode":null,"errorMessage":"unable to make UUID from '%s'","messagePattern":"unable to make UUID from '(.+?)'","errorType":"validation","errorClass":"MarshalException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/db/marshal/LexicalUUIDType.java","lineNumber":121,"sourceCode":"\n        // Lexical UUIDs are stored as just two signed longs. The decoding of these longs flips their sign bit back, so\n        // they can directly be used for constructing the original UUID.\n        return UUIDType.makeUuidBytes(accessor, hiBits, loBits);\n    }\n\n    public ByteBuffer fromString(String source) throws MarshalException\n    {\n        // Return an empty ByteBuffer for an empty string.\n        if (source.isEmpty())\n            return ByteBufferUtil.EMPTY_BYTE_BUFFER;\n\n        try\n        {\n            return decompose(UUID.fromString(source));\n        }\n        catch (IllegalArgumentException e)\n        {\n            throw new MarshalException(String.format(\"unable to make UUID from '%s'\", source), e);\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 a string representation of a uuid, but got a %s: %s\", parsed.getClass().getSimpleName(), parsed));\n        }\n    }\n\n    @Override","sourceCodeStart":103,"sourceCodeEnd":139,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/db/marshal/LexicalUUIDType.java#L103-L139","documentation":"LexicalUUIDType.fromString parses a string into a UUID. If the string is not a valid textual UUID representation, UUID.fromString throws IllegalArgumentException, which is wrapped in a MarshalException with this message.","triggerScenarios":"Passing a non-UUID string to fromString, e.g. via INSERT/UPDATE with a string literal for a uuid column, or fromJSONObject delegating to fromString with user text like 'abc' or '123' (missing dashes/length, invalid hex characters).","commonSituations":"Application inserts hand-built string values into uuid columns; JSON payloads contain string IDs generated by another system that are not canonical UUID format; typos or truncated UUIDs.","solutions":["Ensure the string is a valid UUID in canonical 8-4-4-4-12 hex format before passing it (e.g. UUID.fromString as a pre-check in the client).","Use UUID.randomUUID() or another generator rather than hand-constructing the string.","If accepting arbitrary IDs, validate with a regex or try/catch and return a user-friendly validation error before sending the query."],"exampleFix":"// before\nString id = row.get(\"id\"); // e.g. \"12345\"\ninsert.bind(id);\n// after\nUUID uuid = UUID.fromString(id); // throws IllegalArgumentException early if malformed\ninsert.bind(uuid);","handlingStrategy":"try-catch","validationCode":"private static final Pattern UUID_RE = Pattern.compile(\"^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$\");\nboolean valid = source != null && UUID_RE.matcher(source).matches();","typeGuard":"boolean isUuidString(Object o) { return o instanceof String && UUID_RE.matcher((String) o).matches(); }","tryCatchPattern":"try { term = lexicalType.fromString(source); } catch (MarshalException e) { throw new BadRequestException(\"Invalid UUID: \" + source); }","preventionTips":["Generate UUIDs with UUID.randomUUID() instead of hand-built strings.","Validate IDs against the canonical 8-4-4-4-12 regex at API ingress.","Normalize (lowercase, trim) UUID strings before binding them to queries."],"tags":["uuid","parsing","marshal","type-conversion"],"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"}