{"record":{"id":"00170b7a4dbd2393","repo":"apache/cassandra","slug":"invalid-version-for-timeuuid-type-0x-s","errorCode":null,"errorMessage":"Invalid version for TimeUUID type: 0x%s","messagePattern":"Invalid version for TimeUUID type: 0x(.+?)","errorType":"validation","errorClass":"MarshalException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/utils/TimeUUID.java","lineNumber":345,"sourceCode":"    public int compareTo(TimeUUID that)\n    {\n        return this.uuidTimestamp != that.uuidTimestamp\n               ? Long.compare(this.uuidTimestamp, that.uuidTimestamp)\n               : Long.compare(this.lsb, that.lsb);\n    }\n\n    protected static abstract class AbstractSerializer<T extends TimeUUID> extends TypeSerializer<T>\n    {\n        public <V> void validate(V value, ValueAccessor<V> accessor) throws MarshalException\n        {\n            if (accessor.isEmpty(value))\n                return;\n\n            if (accessor.size(value) != 16)\n                throw new MarshalException(String.format(\"UUID should be 16 or 0 bytes (%d)\", accessor.size(value)));\n\n            if ((accessor.getByte(value, 6) & 0xf0) != 0x10)\n                throw new MarshalException(String.format(\"Invalid version for TimeUUID type: 0x%s\", Integer.toHexString((accessor.getByte(value, 0) >> 4) & 0xf)));\n        }\n\n        public String toString(T value)\n        {\n            return value == null ? \"\" : value.toString();\n        }\n\n        public ByteBuffer serialize(T value)\n        {\n            if (value == null)\n                return EMPTY_BYTE_BUFFER;\n            ByteBuffer buffer = ByteBuffer.allocate(16);\n            buffer.putLong(value.msb());\n            buffer.putLong(value.lsb());\n            buffer.flip();\n            return buffer;\n        }\n    }","sourceCodeStart":327,"sourceCodeEnd":363,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/utils/TimeUUID.java#L327-L363","documentation":"TimeUUIDType.validate() also verifies the RFC 4122 version nibble: byte 6's high nibble must be 0x1 (time-based). If not, it throws this MarshalException including the hex version read from the value. This rejects random (v4) or other UUID kinds passed as timeuuid.","triggerScenarios":"Writing a version-4 (random) UUID or v3/v5 UUID into a timeuuid column — the 16-byte length check passes but the version nibble at byte 6 is not 0x10.","commonSituations":"See trigger scenarios.","solutions":["Generate proper time-uuids (TimeUUID.Generator / driver TimeUuid / UUIDs.timeBased()) instead of random UUIDs","Use the correct driver codec for timeuuid columns so version is enforced client-side","If the value must be a random UUID, change the column type to uuid, not timeuuid","Pre-validate in application: (bytes[6] & 0xf0) == 0x10"],"exampleFix":"// before\nstmt.setUuid(i, UUID.randomUUID()); // v4 -> MarshalException\n// after\nstmt.setUuid(i, UUIDs.timeBased()); // v1-style time-based UUID","handlingStrategy":"validation","validationCode":"boolean isTimeUuid(byte[] b) { return b != null && b.length == 16 && (b[6] & 0xf0) == 0x10; }","typeGuard":"boolean isTimeUuid(java.util.UUID u) { return (u.toString().charAt(14)) == '1'; } // version nibble in canonical string","tryCatchPattern":"try { session.execute(insert.bind(value)); } catch (InvalidQueryException e) { if (e.getMessage().contains(\"Invalid version for TimeUUID\")) { /* regenerate as v1 time-based UUID */ } else throw e; }","preventionTips":["Generate timeuuids with UUIDs.timeBased()/TimeUUID.Generator, not randomUUID","Use the driver's TimeUuidCodec for timeuuid columns","Use the plain uuid type when version-4 UUIDs are intended","Pre-validate version nibble in client code before writes"],"tags":["timeuuid","validation","uuid-version"],"backgroundTag":"schema-validation-failed","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"}