{"record":{"id":"8a88445346dc39b4","repo":"apache/cassandra","slug":"cannot-parse-32-bits-float-value-from-s","errorCode":null,"errorMessage":"Cannot parse 32-bits float value from \"%s\"","messagePattern":"Cannot parse 32-bits float value from \"(.+?)\"","errorType":"validation","errorClass":"InvalidTypeException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/functions/types/TypeCodec.java","lineNumber":1447,"sourceCode":"\n        @Override\n        public int serializedSize()\n        {\n            return 4;\n        }\n\n        @Override\n        public Float parse(String value)\n        {\n            try\n            {\n                return value == null || value.isEmpty() || value.equalsIgnoreCase(\"NULL\")\n                       ? null\n                       : Float.parseFloat(value);\n            }\n            catch (NumberFormatException e)\n            {\n                throw new InvalidTypeException(\n                String.format(\"Cannot parse 32-bits float value from \\\"%s\\\"\", value));\n            }\n        }\n\n        @Override\n        public String format(Float value)\n        {\n            if (value == null) return \"NULL\";\n            return Float.toString(value);\n        }\n\n        @Override\n        public ByteBuffer serializeNoBoxing(float value, ProtocolVersion protocolVersion)\n        {\n            ByteBuffer bb = ByteBuffer.allocate(4);\n            bb.putFloat(0, value);\n            return bb;\n        }","sourceCodeStart":1429,"sourceCodeEnd":1465,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/functions/types/TypeCodec.java#L1429-L1465","documentation":"Thrown by FloatCodec.parse when the string form of a value cannot be converted to a 32-bit float with Float.parseFloat. The driver uses parse() when deserializing from string representations (e.g. string-based protocols or Literal binding), and any non-numeric or out-of-range text raises this InvalidTypeException.","triggerScenarios":"Calling FloatCodec.parse(String) or binding/reading a CQL float from a String value whose text is not a valid Java float literal (e.g. \"abc\", \"1,5\", \"1e999\" ranges that overflow).","commonSituations":"Passing user-supplied or localized text (comma decimal separators) into a statement, reading a float column that actually contains text, or copy-pasting formatted numbers with currency symbols or thousands separators.","solutions":["Validate the string with Float.parseFloat in a try block or a regex before handing it to the codec.","Normalize locale-specific formatting first: replace ',' decimal separators and strip spaces/symbols.","Use prepared statements with typed setFloat(...) instead of string parsing.","Catch InvalidTypeException around parse and surface a user-friendly validation message."],"exampleFix":"// before\nFloat v = new FloatCodec().parse(userInput);\n// after\nString normalized = userInput.trim().replace(',', '.');\nif (!normalized.matches(\"[+-]?(\\\\d+(\\\\.\\\\d*)?|\\\\.\\\\d+)([eE][+-]?\\\\d+)?\")) {\n    throw new IllegalArgumentException(\"Not a float: \" + userInput);\n}\nFloat v = new FloatCodec().parse(normalized);","handlingStrategy":"validation","validationCode":"boolean isParsableFloat(String s) {\n    if (s == null || s.isEmpty() || s.equalsIgnoreCase(\"NULL\")) return true;\n    return s.trim().matches(\"[+-]?(\\\\d+(\\\\.\\\\d*)?|\\\\.\\\\d+)([eE][+-]?\\\\d+)?\");\n}","typeGuard":null,"tryCatchPattern":"try { Float v = codec.parse(value); }\ncatch (InvalidTypeException e) {\n    throw new IllegalArgumentException(\"Invalid float literal: \" + value, e);\n}","preventionTips":["Normalize locale formats (comma decimals, thousands separators) before parsing.","Use prepared statements with setFloat instead of string parsing.","Regex-validate numeric text at the input boundary.","Never feed formatted/display strings back into parse()."],"tags":["parsing","type-codec","string-conversion","float"],"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-17T15:17:12.973Z"}