{"record":{"id":"01328b2435dd0916","repo":"apache/cassandra","slug":"cannot-parse-32-bits-int-value-from-s","errorCode":null,"errorMessage":"Cannot parse 32-bits int value from \"%s\"","messagePattern":"Cannot parse 32-bits int value from \"(.+?)\"","errorType":"exception","errorClass":"InvalidTypeException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/functions/types/TypeCodec.java","lineNumber":1682,"sourceCode":"\n        @Override\n        public int serializedSize()\n        {\n            return 4;\n        }\n\n        @Override\n        public Integer parse(String value)\n        {\n            try\n            {\n                return value == null || value.isEmpty() || value.equalsIgnoreCase(\"NULL\")\n                       ? null\n                       : Integer.parseInt(value);\n            }\n            catch (NumberFormatException e)\n            {\n                throw new InvalidTypeException(\n                String.format(\"Cannot parse 32-bits int value from \\\"%s\\\"\", value));\n            }\n        }\n\n        @Override\n        public String format(Integer value)\n        {\n            if (value == null) return \"NULL\";\n            return Integer.toString(value);\n        }\n\n        @Override\n        public ByteBuffer serializeNoBoxing(int value, ProtocolVersion protocolVersion)\n        {\n            ByteBuffer bb = ByteBuffer.allocate(4);\n            bb.putInt(0, value);\n            return bb;\n        }","sourceCodeStart":1664,"sourceCodeEnd":1700,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/functions/types/TypeCodec.java#L1664-L1700","documentation":"Thrown by TypeCodec.IntCodec.parse(String) when a string literal intended for a CQL int (32-bit) column cannot be parsed by Integer.parseInt, i.e. it is not a valid signed 32-bit integer literal. The library wraps the NumberFormatException in InvalidTypeException because the value violates the CQL int literal grammar. Callers are typically building query strings or simple statements via codec.parse().","triggerScenarios":"Calling IntCodec.parse() with a non-numeric string (e.g. \"12a\"), a decimal (\"3.14\"), an empty-after-unquoting token, or an out-of-int-range literal like \"3000000000\"; the codec maps DataType.cint() so any parse path for cint literals funnels here.","commonSituations":"Hand-building INSERT/UPDATE literals where user input is concatenated unvalidated; reading values from config/CSV/JSON that were assumed numeric; locale-formatted numbers containing spaces or separators; pasting a bigint or float literal into an int column.","solutions":["Validate the string is a signed 32-bit integer before calling parse (e.g. Long/Integer.parseInt in a try block, or regex ^-?\\d{1,10}$ plus range check).","Fix the source data: strip whitespace, remove thousands separators, or correct the literal.","If the value can exceed int range, change the CQL column to bigint/varint and use the matching codec.","Catch InvalidTypeException at the statement-building boundary and surface a user-facing validation message."],"exampleFix":"// before\nInteger n = TypeCodec.cint().parse(userInput);\n// after\nString cleaned = userInput == null ? null : userInput.trim();\nInteger n;\ntry { n = cleaned == null ? null : Integer.parseInt(cleaned); }\ncatch (NumberFormatException e) { throw new IllegalArgumentException(\"Expected a 32-bit int, got: \" + userInput, e); }","handlingStrategy":"validation","validationCode":"static boolean isCqlInt(String s) {\n    if (s == null) return false;\n    String t = s.trim();\n    if (!t.matches(\"-?\\\\d+\")) return false;\n    try { Integer.parseInt(t); return true; } catch (NumberFormatException e) { return false; }\n}","typeGuard":null,"tryCatchPattern":"try {\n    Integer v = TypeCodec.cint().parse(raw);\n} catch (InvalidTypeException e) {\n    log.warn(\"Bad int literal: {}\", e.getMessage());\n    throw new BadRequest(\"Expected a 32-bit integer\");\n}","preventionTips":["Never concatenate raw user input into CQL literals; validate numerics first.","Prefer bound statements with typed parameters over string parsing.","Trim and normalize numeric strings (remove separators/spaces) before parsing.","Check the column type matches the codec (int vs bigint vs varint)."],"tags":["cassandra","codec","invalid-type-exception","parsing","cql-int"],"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-14T16:17:12.679Z"}