{"record":{"id":"9f66c4c25a9e0ed3","repo":"apache/cassandra","slug":"unable-to-make-byte-from-s","errorCode":null,"errorMessage":"Unable to make byte from '%s'","messagePattern":"Unable to make byte from '(.+?)'","errorType":"validation","errorClass":"MarshalException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/db/marshal/ByteType.java","lineNumber":81,"sourceCode":"    {\n        return ByteSourceInverse.getOptionalSignedFixedLength(accessor, comparableBytes, 1);\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        byte b;\n\n        try\n        {\n            b = Byte.parseByte(source);\n        }\n        catch (Exception e)\n        {\n            throw new MarshalException(String.format(\"Unable to make byte from '%s'\", source), e);\n        }\n\n        return decompose(b);\n    }\n\n    public Term fromJSONObject(Object parsed) throws MarshalException\n    {\n        if (parsed instanceof String || parsed instanceof Number)\n            return new Constants.Value(fromString(String.valueOf(parsed)));\n\n        throw new MarshalException(String.format(\n                \"Expected a byte value, but got a %s: %s\", parsed.getClass().getSimpleName(), parsed));\n    }\n\n    @Override\n    public String toJSONString(ByteBuffer buffer, ProtocolVersion protocolVersion)\n    {\n        return getSerializer().deserialize(buffer).toString();","sourceCodeStart":63,"sourceCodeEnd":99,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/db/marshal/ByteType.java#L63-L99","documentation":"ByteType.fromString throws this when the source string cannot be parsed by Byte.parseByte, i.e. it is not an integer in the signed 8-bit range [-128, 127]. The underlying parse failure (NumberFormatException etc.) is chained as the cause.","triggerScenarios":"INSERT of a value like '300', 'abc', '1.5', or '-200' into a byte column; fromJSONObject passing a numeric string out of byte range; binding values with whitespace or sign errors.","commonSituations":"Migrating from int columns to byte columns where values exceed 127; typos and decimals in manual cqlsh sessions; application code not validating ranges before bind; CSV imports with unparsed numeric formats.","solutions":["Supply an integer literal within -128..127","Change the column type to smallint/int if larger values are needed","Range-check in application code before casting to byte","Trim the input and reject non-integer strings before binding"],"exampleFix":"// before\nINSERT INTO t (k, v) VALUES (1, 300); -- byte column\n// after\nINSERT INTO t (k, v) VALUES (1, 42); -- or ALTER TABLE t ALTER v TYPE int;","handlingStrategy":"validation","validationCode":"public static void assertByte(String s) {\n    int v = Integer.parseInt(s.trim());\n    if (v < Byte.MIN_VALUE || v > Byte.MAX_VALUE)\n        throw new IllegalArgumentException(\"Out of byte range: \" + v);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Range-check before binding to byte columns","Pick smallint/int for wider ranges at schema design time","Strip whitespace from numeric input","Handle out-of-range values with an explicit rounding/reject policy in ETL"],"tags":["cassandra","marshal","byte","range"],"backgroundTag":"value-out-of-range","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"}