{"record":{"id":"80286c7889a8d248","repo":"apache/cassandra","slug":"unable-to-make-int-from-s-80286c","errorCode":null,"errorMessage":"unable to make int from '%s'","messagePattern":"unable to make int from '(.+?)'","errorType":"validation","errorClass":"MarshalException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/db/marshal/IntegerType.java","lineNumber":467,"sourceCode":"\n        return buf;\n    }\n\n    public ByteBuffer fromString(String source) throws MarshalException\n    {\n        // Return an empty ByteBuffer for an empty string.\n        if (source.isEmpty())\n            return ByteBufferUtil.EMPTY_BYTE_BUFFER;\n\n        BigInteger integerType;\n\n        try\n        {\n            integerType = new BigInteger(source);\n        }\n        catch (Exception e)\n        {\n            throw new MarshalException(String.format(\"unable to make int from '%s'\", source), e);\n        }\n\n        return decompose(integerType);\n    }\n\n    @Override\n    public Term fromJSONObject(Object parsed) throws MarshalException\n    {\n        try\n        {\n            return new Constants.Value(getSerializer().serialize(new BigInteger(parsed.toString())));\n        }\n        catch (NumberFormatException exc)\n        {\n            throw new MarshalException(String.format(\n                    \"Value '%s' is not a valid representation of a varint value\", parsed));\n        }\n    }","sourceCodeStart":449,"sourceCodeEnd":485,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/db/marshal/IntegerType.java#L449-L485","documentation":"IntegerType (varint) fromString() constructs a BigInteger from the source text with new BigInteger(source); any parse failure is wrapped in this MarshalException. The string must be a valid arbitrary-precision integer literal (optional sign followed by digits).","triggerScenarios":"Calling IntegerType.instance.fromString(\"12.5\") or fromString(\"\") or fromString(\"0x1F\") — new BigInteger throws NumberFormatException, rethrown as MarshalException.","commonSituations":"Passing decimal floats or hex strings to varint columns; empty strings from blank CSV fields; locale-formatted numbers with grouping separators.","solutions":["Ensure the string contains only an optional +/- sign and decimal digits","Parse floats into DecimalType (decimal) instead of IntegerType (varint)","Strip formatting (spaces, commas) and validate with a regex ^[+-]?\\d+$ before calling fromString","Catch MarshalException and report the invalid literal"],"exampleFix":"// before\nByteBuffer v = IntegerType.instance.fromString(\"3.14\"); // throws\n// after\nif (!raw.matches(\"[+-]?\\\\d+\")) throw new IllegalArgumentException(\"varint literal required\");\nByteBuffer v = IntegerType.instance.fromString(\"3\"); // or DecimalType for 3.14","handlingStrategy":"validation","validationCode":"if (!source.matches(\"[+-]?\\\\d+\"))\n    throw new IllegalArgumentException(\"Not a valid varint literal: \" + source);","typeGuard":"static boolean isBigIntegerLiteral(String s) { try { new BigInteger(s); return true; } catch (NumberFormatException e) { return false; } }","tryCatchPattern":"try { IntegerType.instance.fromString(source); } catch (MarshalException e) { /* invalid varint literal; reject or route to decimal type */ }","preventionTips":["Use decimal columns for fractional values, varint only for integers","Strip locale formatting (commas, spaces) before parsing","Reject empty strings before parsing","Regex-validate integer literals at ingestion boundaries"],"tags":["cassandra","marshalling","varint","number-format"],"backgroundTag":"number-format-exception","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-14T21:17:11.552Z"}