{"record":{"id":"a4ff8504f7029a89","repo":"apache/cassandra","slug":"in-call-to-function-s-value-0x-s-is-not-a-valid","errorCode":null,"errorMessage":"In call to function %s, value 0x%s is not a valid binary representation for type %s","messagePattern":"In call to function (.+?), value 0x(.+?) is not a valid binary representation for type (.+?)","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/functions/BytesConversionFcts.java","lineNumber":120,"sourceCode":"                  toType.getType().udfType(),\n                  BytesType.instance);\n            this.toType = toType;\n        }\n\n        @Override\n        public ByteBuffer execute(Arguments arguments)\n        {\n            ByteBuffer val = arguments.get(0);\n\n            if (val != null)\n            {\n                try\n                {\n                    toType.getType().validate(val);\n                }\n                catch (MarshalException e)\n                {\n                    throw new InvalidRequestException(String.format(\"In call to function %s, value 0x%s is not a \" +\n                                                                    \"valid binary representation for type %s\",\n                                                                    name, ByteBufferUtil.bytesToHex(val), toType));\n                }\n            }\n\n            return val;\n        }\n\n        @Override\n        public NativeFunction withLegacyName()\n        {\n            return new FromBlobFunction(toType, true);\n        }\n    }\n}\n","sourceCodeStart":102,"sourceCodeEnd":136,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/functions/BytesConversionFcts.java#L102-L136","documentation":"Thrown by the blob conversion functions (BytesConversionFcts) when validating that a raw blob is a valid binary representation of the target type. If toType.validate throws MarshalException, the call is rejected with InvalidRequestException instead of returning garbage.","triggerScenarios":"Calling conversion functions like blobastext, textasblob, intasblob, or the generic blob-to-type function with bytes that fail the target type's validation (wrong byte count for fixed-size types, invalid encoding).","commonSituations":"Reinterpreting a blob produced for one type as another type (e.g. a 4-byte int blob passed where a UUID is expected); hand-crafted hex literals with wrong length; deserializing columns after a schema type change.","solutions":["Ensure the blob was produced by the matching *asblob function for the target type.","Check the hex literal length matches the type's serialized size (int=4 bytes, bigint=8, uuid=16).","If the type changed, migrate data via a correct re-serialization rather than a direct blob cast."],"exampleFix":"// before: SELECT intastext(some_blob_col) ... where blob holds a 16-byte UUID\n// after\nSELECT uuidastext(some_blob_col) ... -- use the conversion matching the actual type","handlingStrategy":"validation","validationCode":"// Java: verify size before conversion\n// int blob must be 4 bytes, bigint 8, uuid 16\nif (val.remaining() != 4) throw new IllegalArgumentException(\"expected 4-byte int blob\");","typeGuard":null,"tryCatchPattern":"catch (InvalidRequestException e) { if (e.getMessage().contains(\"not a valid binary representation\")) { log.warn(\"blob/type mismatch\"); } }","preventionTips":["Only feed blobs produced by the matching *asblob function.","Track the original type of blob columns in metadata.","Check serialized sizes per type before conversion."],"tags":["cassandra","cql","function","marshalling"],"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"}