{"record":{"id":"dff159ebd2b155e6","repo":"apache/cassandra","slug":"cannot-parse-s-as-hex-bytes-dff159","errorCode":null,"errorMessage":"cannot parse '%s' as hex bytes","messagePattern":"cannot parse '(.+?)' as hex bytes","errorType":"validation","errorClass":"MarshalException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/db/marshal/VectorType.java","lineNumber":280,"sourceCode":"    }\n\n    // vector of nested types is hard to parse, so fall back to bytes string matching ListType\n    @Override\n    public <V> String getString(V value, ValueAccessor<V> accessor)\n    {\n        return BytesType.instance.getString(value, accessor);\n    }\n\n    @Override\n    public ByteBuffer fromString(String source) throws MarshalException\n    {\n        try\n        {\n            return ByteBufferUtil.hexToBytes(source);\n        }\n        catch (NumberFormatException e)\n        {\n            throw new MarshalException(String.format(\"cannot parse '%s' as hex bytes\", source), e);\n        }\n    }\n\n    @Override\n    public List<AbstractType<?>> subTypes()\n    {\n        return Collections.singletonList(elementType);\n    }\n\n    @Override\n    public String toJSONString(ByteBuffer buffer, ProtocolVersion protocolVersion)\n    {\n        return toJSONString(buffer, ByteBufferAccessor.instance, protocolVersion);\n    }\n\n    @Override\n    public <V> String toJSONString(V value, ValueAccessor<V> accessor, ProtocolVersion protocolVersion)\n    {","sourceCodeStart":262,"sourceCodeEnd":298,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/db/marshal/VectorType.java#L262-L298","documentation":"VectorType.fromString treats its input as a hex-encoded byte string. If the string cannot be parsed as hex, MarshalException is thrown wrapping the NumberFormatException. For vectors this generic string parsing path is rarely the intended entry point — elements are usually provided as literals or JSON.","triggerScenarios":"Calling vectorType.fromString(\"not-hex\") or passing a string containing non-hex characters (or odd-length hex) directly to fromString.","commonSituations":"Test code or tooling building vector values from strings; cqlsh/scripting paths passing raw strings where hex-encoded binary is expected.","solutions":["Pass a valid hex-encoded string (even length, 0-9a-fA-F only)","Use elementType-appropriate parsing (e.g. fromJSONObject with a JSON list) instead of fromString for vector literals","Pre-clean/validate the string with a hex regex before calling fromString"],"exampleFix":"// before\nByteBuffer buf = vectorType.fromString(\"1,2,3\");\n// after\nTerm term = vectorType.fromJSONObject(Arrays.asList(1, 2, 3));","handlingStrategy":"validation","validationCode":"if (source == null || !source.matches(\"[0-9a-fA-F]*\") || source.length() % 2 != 0)\n    throw new IllegalArgumentException(\"not valid hex: \" + source);","typeGuard":null,"tryCatchPattern":"try { buf = vt.fromString(source); } catch (MarshalException e) { /* fall back to JSON parsing */ }","preventionTips":["Prefer fromJSONObject with a list for vector literals","Validate hex strings before passing to fromString"],"tags":["cassandra","hex","parsing","vector-type"],"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-14T21:17:11.552Z"}