{"record":{"id":"c2bff7f9fbfbc11c","repo":"apache/cassandra","slug":"unable-to-make-bigdecimal-from-s","errorCode":null,"errorMessage":"unable to make BigDecimal from '%s'","messagePattern":"unable to make BigDecimal from '(.+?)'","errorType":"validation","errorClass":"MarshalException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/db/marshal/DecimalType.java","lineNumber":294,"sourceCode":"        accessor.putInt(resultBuf, 0, (int) -base10NonBigDecimalFormatExp);\n        accessor.copyByteArrayTo(mantissaBytes, 0, resultBuf, 4, mantissaBytes.length);\n        return resultBuf;\n    }\n\n    public ByteBuffer fromString(String source) throws MarshalException\n    {\n        // Return an empty ByteBuffer for an empty string.\n        if (source.isEmpty()) return ByteBufferUtil.EMPTY_BYTE_BUFFER;\n\n        BigDecimal decimal;\n\n        try\n        {\n            decimal = new BigDecimal(source);\n        }\n        catch (Exception e)\n        {\n            throw new MarshalException(String.format(\"unable to make BigDecimal from '%s'\", source), e);\n        }\n\n        return decompose(decimal);\n    }\n\n    @Override\n    public Term fromJSONObject(Object parsed) throws MarshalException\n    {\n        try\n        {\n            return new Constants.Value(fromString(Objects.toString(parsed)));\n        }\n        catch (NumberFormatException | MarshalException exc)\n        {\n            throw new MarshalException(String.format(\"Value '%s' is not a valid representation of a decimal value\", parsed));\n        }\n    }\n","sourceCodeStart":276,"sourceCodeEnd":312,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/db/marshal/DecimalType.java#L276-L312","documentation":"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.","triggerScenarios":"Calling fromString with text like '1,5' (comma decimal separator), '1e999999999999' (overflow/exponent issues), or any non-numeric string; fromJSONObject delegates here.","commonSituations":"Locale-formatted numbers (commas) pasted into CQL/JSON input; whitespace or currency symbols; COPY FROM with malformed CSV fields.","solutions":["Provide a plain decimal literal like '123.45' or '-0.001E+10'","Strip locale separators/currency symbols and use '.' as the decimal point","Trim whitespace and validate the literal before insert","Catch MarshalException at the application layer and surface a column-specific message"],"exampleFix":"// before\nDecimalType.instance.fromString(\"1,234.56\");\n// after\nDecimalType.instance.fromString(\"1234.56\");","handlingStrategy":"validation","validationCode":"boolean isDecimalLiteral(String s) { return s != null && s.trim().matches(\"[+-]?\\\\d+(\\\\.\\\\d+)?([eE][+-]?\\\\d+)?\"); }","typeGuard":null,"tryCatchPattern":"try { DecimalType.instance.fromString(s); } catch (MarshalException e) { /* surface column+value in error, skip or fix row */ }","preventionTips":["Use '.' as decimal separator; strip locale formatting before insert","Trim whitespace and disallow currency symbols","Validate decimal literals in ETL before writing"],"tags":["decimal","parsing","marshal"],"backgroundTag":"invalid-number-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"}