apache/cassandra · error · MarshalException

unable to make BigDecimal from '%s'

Error message

unable to make BigDecimal from '%s'

What it means

DecimalType.fromString constructs a BigDecimal from the given source string; any parse failure (NumberFormatException or other) is wrapped in this MarshalException. It means the literal is not a valid decimal representation.

Source

Thrown at src/java/org/apache/cassandra/db/marshal/DecimalType.java:294

        accessor.putInt(resultBuf, 0, (int) -base10NonBigDecimalFormatExp);
        accessor.copyByteArrayTo(mantissaBytes, 0, resultBuf, 4, mantissaBytes.length);
        return resultBuf;
    }

    public ByteBuffer fromString(String source) throws MarshalException
    {
        // Return an empty ByteBuffer for an empty string.
        if (source.isEmpty()) return ByteBufferUtil.EMPTY_BYTE_BUFFER;

        BigDecimal decimal;

        try
        {
            decimal = new BigDecimal(source);
        }
        catch (Exception e)
        {
            throw new MarshalException(String.format("unable to make BigDecimal from '%s'", source), e);
        }

        return decompose(decimal);
    }

    @Override
    public Term fromJSONObject(Object parsed) throws MarshalException
    {
        try
        {
            return new Constants.Value(fromString(Objects.toString(parsed)));
        }
        catch (NumberFormatException | MarshalException exc)
        {
            throw new MarshalException(String.format("Value '%s' is not a valid representation of a decimal value", parsed));
        }
    }

View on GitHub (pinned to 88fd0f6a0e)

Solutions

  1. Provide a plain decimal literal like '123.45' or '-0.001E+10'
  2. Strip locale separators/currency symbols and use '.' as the decimal point
  3. Trim whitespace and validate the literal before insert
  4. Catch MarshalException at the application layer and surface a column-specific message

Example fix

// before
DecimalType.instance.fromString("1,234.56");
// after
DecimalType.instance.fromString("1234.56");
Defensive patterns

Strategy: validation

Validate before calling

boolean isDecimalLiteral(String s) { return s != null && s.trim().matches("[+-]?\\d+(\\.\\d+)?([eE][+-]?\\d+)?"); }

Try / catch

try { DecimalType.instance.fromString(s); } catch (MarshalException e) { /* surface column+value in error, skip or fix row */ }

Prevention

When it happens

Trigger: Calling fromString with text like '1,5' (comma decimal separator), '1e999999999999' (overflow/exponent issues), or any non-numeric string; fromJSONObject delegates here.

Common situations: Locale-formatted numbers (commas) pasted into CQL/JSON input; whitespace or currency symbols; COPY FROM with malformed CSV fields.

Related errors


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