{"record":{"id":"f43c43588c9a0150","repo":"apache/cassandra","slug":"invalid-8-bits-integer-value-expecting-1-byte-but","errorCode":null,"errorMessage":"Invalid 8-bits integer value, expecting 1 byte but got %d","messagePattern":"Invalid 8-bits integer value, expecting 1 byte but got (.+?)","errorType":"exception","errorClass":"InvalidTypeException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/functions/types/TypeCodec.java","lineNumber":1589,"sourceCode":"        {\n            if (value == null) return \"NULL\";\n            return Byte.toString(value);\n        }\n\n        @Override\n        public ByteBuffer serializeNoBoxing(byte value, ProtocolVersion protocolVersion)\n        {\n            ByteBuffer bb = ByteBuffer.allocate(1);\n            bb.put(0, value);\n            return bb;\n        }\n\n        @Override\n        public byte deserializeNoBoxing(ByteBuffer bytes, ProtocolVersion protocolVersion)\n        {\n            if (bytes == null || bytes.remaining() == 0) return 0;\n            if (bytes.remaining() != 1)\n                throw new InvalidTypeException(\n                \"Invalid 8-bits integer value, expecting 1 byte but got \" + bytes.remaining());\n\n            return bytes.get(bytes.position());\n        }\n    }\n\n    /**\n     * This codec maps a CQL {@link DataType#smallint()} to a Java {@link Short}.\n     */\n    private static class SmallIntCodec extends PrimitiveShortCodec\n    {\n\n        private static final SmallIntCodec instance = new SmallIntCodec();\n\n        private SmallIntCodec()\n        {\n            super(smallint());\n        }","sourceCodeStart":1571,"sourceCodeEnd":1607,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/functions/types/TypeCodec.java#L1571-L1607","documentation":"Thrown by ByteCodec.deserializeNoBoxing when the ByteBuffer does not contain exactly 1 byte, the wire size of a CQL tinyint. Null/empty buffers return 0; any other length is invalid for an 8-bit signed integer.","triggerScenarios":"Calling ByteCodec.deserializeNoBoxing(bytes, protocolVersion) with a ByteBuffer whose remaining() is 2, 4, 8, etc., typically deserializing a smallint/int/bigint column as tinyint.","commonSituations":"Column type changed from int to tinyint (or vice versa) in one environment but not another, manual UDT/collection element parsing with wrong codec, or importing legacy data.","solutions":["Check the column's declared CQL type and use the matching codec (ShortCodec for smallint, IntCodec for int).","Log bytes.remaining() to infer the actual encoded width (2/4/8) and switch codecs accordingly.","Use the row-level typed getters (getByte/getShort/getInt) so type selection is automatic.","Migrate data to the intended type if producers and consumers disagree."],"exampleFix":"// before\nbyte b = new ByteCodec().deserializeNoBoxing(bytes, ProtocolVersion.V4);\n// after\nswitch (bytes.remaining()) {\n    case 1: return new ByteCodec().deserializeNoBoxing(bytes, ProtocolVersion.V4);\n    case 2: return (byte) new ShortCodec().deserializeNoBoxing(bytes, ProtocolVersion.V4);\n    case 4: return (byte) new IntCodec().deserializeNoBoxing(bytes, ProtocolVersion.V4);\n    default: throw new IllegalArgumentException(\"Unexpected width \" + bytes.remaining());\n}","handlingStrategy":"validation","validationCode":"if (bytes == null || bytes.remaining() == 0) return (byte) 0;\nif (bytes.remaining() != 1)\n    throw new IllegalArgumentException(\"Expected 1 byte for tinyint, got \" + bytes.remaining());","typeGuard":"boolean isByteSized(ByteBuffer b) { return b != null && (b.remaining() == 0 || b.remaining() == 1); }","tryCatchPattern":"try { return codec.deserializeNoBoxing(bytes, protocolVersion); }\ncatch (InvalidTypeException e) {\n    log.warn(\"Tinyint deserialization failed: {} bytes\", bytes.remaining());\n    return (byte) 0;\n}","preventionTips":["Match codec width to column type (1/2/4/8 bytes).","Use typed row getters rather than manual codecs.","Watch for ALTER TABLE type changes across environments.","Log remaining() to diagnose width mismatches."],"tags":["serialization","tinyint","bytebuffer","deserialization"],"backgroundTag":"type-mismatch","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"}