apache/cassandra · error · InvalidTypeException

Cannot parse 32-bits float value from

Error message

Cannot parse 32-bits float value from "%s"

What it means

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.

Solutions

  1. Validate the string with Float.parseFloat in a try block or a regex before handing it to the codec.
  2. Normalize locale-specific formatting first: replace ',' decimal separators and strip spaces/symbols.
  3. Use prepared statements with typed setFloat(...) instead of string parsing.
  4. Catch InvalidTypeException around parse and surface a user-friendly validation message.

Example fix

// before
Float v = new FloatCodec().parse(userInput);
// after
String normalized = userInput.trim().replace(',', '.');
if (!normalized.matches("[+-]?(\\d+(\\.\\d*)?|\\.\\d+)([eE][+-]?\\d+)?")) {
    throw new IllegalArgumentException("Not a float: " + userInput);
}
Float v = new FloatCodec().parse(normalized);
Defensive patterns

Strategy: validation

Validate before calling

boolean isParsableFloat(String s) {
    if (s == null || s.isEmpty() || s.equalsIgnoreCase("NULL")) return true;
    return s.trim().matches("[+-]?(\\d+(\\.\\d*)?|\\.\\d+)([eE][+-]?\\d+)?");
}

Try / catch

try { Float v = codec.parse(value); }
catch (InvalidTypeException e) {
    throw new IllegalArgumentException("Invalid float literal: " + value, e);
}

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10). Data as JSON: /api/errors/8a88445346dc39b4. Report an issue: GitHub.

Appendix: source

Thrown at src/java/org/apache/cassandra/cql3/functions/types/TypeCodec.java:1447

        @Override
        public int serializedSize()
        {
            return 4;
        }

        @Override
        public Float parse(String value)
        {
            try
            {
                return value == null || value.isEmpty() || value.equalsIgnoreCase("NULL")
                       ? null
                       : Float.parseFloat(value);
            }
            catch (NumberFormatException e)
            {
                throw new InvalidTypeException(
                String.format("Cannot parse 32-bits float value from \"%s\"", value));
            }
        }

        @Override
        public String format(Float value)
        {
            if (value == null) return "NULL";
            return Float.toString(value);
        }

        @Override
        public ByteBuffer serializeNoBoxing(float value, ProtocolVersion protocolVersion)
        {
            ByteBuffer bb = ByteBuffer.allocate(4);
            bb.putFloat(0, value);
            return bb;
        }

View on GitHub (pinned to 88fd0f6a0e)