{"record":{"id":"97e3812b90ee635a","repo":"apache/cassandra","slug":"unable-to-make-int-from-s","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/Int32Type.java","lineNumber":99,"sourceCode":"    {\n        return ByteSourceInverse.getOptionalSignedFixedLength(accessor, comparableBytes, 4);\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        int int32Type;\n\n        try\n        {\n            int32Type = Integer.parseInt(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(int32Type);\n    }\n\n    @Override\n    public Term fromJSONObject(Object parsed) throws MarshalException\n    {\n        try\n        {\n            if (parsed instanceof String)\n                return new Constants.Value(fromString((String) parsed));\n\n            Number parsedNumber = (Number) parsed;\n            if (!(parsedNumber instanceof Integer))\n                throw new MarshalException(String.format(\"Expected an int value, but got a %s: %s\", parsed.getClass().getSimpleName(), parsed));\n\n            return new Constants.Value(getSerializer().serialize(parsedNumber.intValue()));","sourceCodeStart":81,"sourceCodeEnd":117,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/db/marshal/Int32Type.java#L81-L117","documentation":"Int32Type.fromString() parses a 32-bit integer from its string form with Integer.parseInt; any parse failure (non-numeric text or values outside int range) is wrapped in this MarshalException with the offending source. The underlying exception (NumberFormatException) is attached as the cause.","triggerScenarios":"Calling Int32Type.instance.fromString(\"abc\") or fromString(\"99999999999\") (overflow) directly or via fromJSONObject; Integer.parseInt throws and the catch block raises MarshalException.","commonSituations":"User input placed directly into int columns via cqlsh or drivers using the text protocol; CSV/JSON imports with empty or decorated numeric strings ('1,000', '12 '); using bigint-scale numbers in an int column.","solutions":["Validate the string matches an optional-sign digit sequence and fits in int range before calling fromString","Use LongType/IntegerType (varint) for values beyond int range","Trim/clean whitespace and thousands separators from input before parsing","Catch MarshalException and report the invalid literal to the caller"],"exampleFix":"// before\nByteBuffer v = Int32Type.instance.fromString(\"1,000\"); // throws\n// after\nString s = raw.trim().replace(\",\", \"\");\nint n = Integer.parseInt(s); // validate first; fits in int\nByteBuffer v = Int32Type.instance.fromString(String.valueOf(n));","handlingStrategy":"validation","validationCode":"try { Integer.parseInt(source.trim()); } catch (NumberFormatException e) { throw new IllegalArgumentException(\"Not a valid 32-bit int: \" + source); }","typeGuard":"static boolean isInt32Literal(String s) { try { Integer.parseInt(s.trim()); return true; } catch (NumberFormatException e) { return false; } }","tryCatchPattern":"try { Int32Type.instance.fromString(source); } catch (MarshalException e) { /* report invalid int literal; check cause for range vs format */ }","preventionTips":["Trim and strip formatting from numeric input before parsing","Use bigint/varint columns for values outside int range","Never feed raw user input straight into fromString","Validate CSV/JSON numeric fields at ingestion time"],"tags":["cassandra","marshalling","int","number-format"],"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-14T21:17:11.552Z"}