{"record":{"id":"bfbc9d95053f9135","repo":"apache/cassandra","slug":"timeuuid-supports-only-version-1-uuids","errorCode":null,"errorMessage":"TimeUUID supports only version 1 UUIDs","messagePattern":"TimeUUID supports only version 1 UUIDs","errorType":"validation","errorClass":"MarshalException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/db/marshal/AbstractTimeUUIDType.java","lineNumber":163,"sourceCode":"\n    protected static long reorderBackTimestampBytes(long input)\n    {\n        // In a time-based UUID the high bits are significantly more shuffled than in other UUIDs - if [X] represents a\n        // 16-bit tuple, [1][2][3][4] should become [3][4][2][1].\n        // See the UUID Javadoc (and more specifically the high bits layout of a Leach-Salz UUID) to understand the\n        // reasoning behind this bit twiddling in the first place (in the context of comparisons).\n        return (input << 32)\n               | ((input >>> 16) & 0xFFFF0000L)\n               | (input >>> 48);\n    }\n\n    public ByteBuffer fromString(String source) throws MarshalException\n    {\n        ByteBuffer parsed = UUIDType.parse(source);\n        if (parsed == null)\n            throw new MarshalException(String.format(\"Unknown timeuuid representation: %s\", source));\n        if (parsed.remaining() == 16 && UUIDType.version(parsed) != 1)\n            throw new MarshalException(\"TimeUUID supports only version 1 UUIDs\");\n        return parsed;\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(\n                    String.format(\"Expected a string representation of a timeuuid, but got a %s: %s\", parsed.getClass().getSimpleName(), parsed));\n        }\n    }\n\n    public CQL3Type asCQL3Type()","sourceCodeStart":145,"sourceCodeEnd":181,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/db/marshal/AbstractTimeUUIDType.java#L145-L181","documentation":"Fired in AbstractTimeUUIDType.fromString when parsing a CQL literal: the UUID is valid but its version nibble is not 1, so it is a random (v4) or other UUID, not a timeuuid. The string is rejected because only version-1 (time-based) UUIDs can be stored in a timeuuid column.","triggerScenarios":"Calling AbstractTimeUUIDType.fromString (directly or via fromJSONObject/CQL literals) with a valid UUID string whose version field is 2-5, e.g. a version-4 random UUID string.","commonSituations":"Passing UUID.randomUUID().toString() into a timeuuid column; mixed-up column types in schema migration; ORM code that shares one UUID generator for uuid and timeuuid columns.","solutions":["Generate a v1 time UUID (UUIDGen.getTimeUUID()) for timeuuid columns.","Validate client-side that uuid.version() == 1 before binding the parameter.","Alter the column to type uuid if v4 UUIDs are the real intent."],"exampleFix":"// before\nUUID id = UUID.randomUUID();\n// after\nif (id.version() != 1) id = UUIDGen.getTimeUUID();","handlingStrategy":"type-guard","validationCode":"if (uuid != null && uuid.version() != 1) uuid = UUIDGen.getTimeUUID();","typeGuard":"boolean isV1(java.util.UUID u) { return u != null && u.version() == 1; }","tryCatchPattern":"catch (MarshalException e) { log.warn(\"rejected non-v1 UUID for timeuuid column\"); uuid = UUIDGen.getTimeUUID(); }","preventionTips":["Keep separate generators/types for uuid vs timeuuid columns.","Assert version()==1 at application boundaries.","Model timeuuid fields with a dedicated TimeUUID type in your client code."],"tags":["uuid","validation","type-mismatch"],"backgroundTag":"invalid-argument-value","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"}