{"record":{"id":"c751e5109ce7842c","repo":"apache/cassandra","slug":"cannot-parse-8-bits-int-value-from-s","errorCode":null,"errorMessage":"Cannot parse 8-bits int value from \"%s\"","messagePattern":"Cannot parse 8-bits int value from \"(.+?)\"","errorType":"validation","errorClass":"InvalidTypeException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/functions/types/TypeCodec.java","lineNumber":1564,"sourceCode":"        private static final TinyIntCodec instance = new TinyIntCodec();\n\n        private TinyIntCodec()\n        {\n            super(tinyint());\n        }\n\n        @Override\n        public Byte parse(String value)\n        {\n            try\n            {\n                return value == null || value.isEmpty() || value.equalsIgnoreCase(\"NULL\")\n                       ? null\n                       : Byte.parseByte(value);\n            }\n            catch (NumberFormatException e)\n            {\n                throw new InvalidTypeException(\n                String.format(\"Cannot parse 8-bits int value from \\\"%s\\\"\", value));\n            }\n        }\n\n        @Override\n        public String format(Byte value)\n        {\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        }","sourceCodeStart":1546,"sourceCodeEnd":1582,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/functions/types/TypeCodec.java#L1546-L1582","documentation":"InvalidTypeException from TinyIntCodec.parse: the string could not be parsed by Byte.parseByte — either outside the 8-bit signed range (-128..127) or not a numeric literal. Empty strings and 'NULL' (case-insensitive) are handled as null before parsing, so this fires only for malformed or out-of-range input.","triggerScenarios":"Calling ByteCodec.parse(String) with values like \"256\", \"-129\", \"1.5\", or \"abc\"; commonly when binding tinyint values from user input or config strings.","commonSituations":"Reading a tinyint column whose data actually exceeds the byte range (values stored as larger ints), localized number strings with separators, or config files supplying plain integers larger than 127.","solutions":["Validate the value fits in -128..127 and is an integer before parsing.","If the data legitimately exceeds the byte range, change the column to smallint/int and use the matching codec.","Parse as a wider type first (Integer.parseInt) and range-check before narrowing to byte.","Catch InvalidTypeException and report which input value and expected range failed."],"exampleFix":"// before\nByte b = new ByteCodec().parse(configValue);\n// after\nint n = Integer.parseInt(configValue.trim());\nif (n < -128 || n > 127)\n    throw new IllegalArgumentException(\"tinyint out of range: \" + n);\nByte b = new ByteCodec().parse(Integer.toString(n));","handlingStrategy":"validation","validationCode":"boolean isValidTinyint(String s) {\n    if (s == null || s.trim().isEmpty() || s.equalsIgnoreCase(\"NULL\")) return true;\n    try { int n = Integer.parseInt(s.trim()); return n >= -128 && n <= 127; }\n    catch (NumberFormatException e) { return false; }\n}","typeGuard":null,"tryCatchPattern":"try { Byte b = codec.parse(value); }\ncatch (InvalidTypeException e) {\n    throw new IllegalArgumentException(\"tinyint must be integer in [-128,127]: \" + value, e);\n}","preventionTips":["Range-check integers before narrowing to byte.","Use int/smallint columns for values beyond -128..127.","Validate numeric config values at startup.","Parse via Integer.parseInt first, then narrow."],"tags":["parsing","tinyint","range","type-codec"],"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-17T15:17:12.973Z"}