{"record":{"id":"687dc0c841122a99","repo":"apache/cassandra","slug":"unable-to-make-short-from-s","errorCode":null,"errorMessage":"Unable to make short from '%s'","messagePattern":"Unable to make short from '(.+?)'","errorType":"exception","errorClass":"MarshalException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/db/marshal/ShortType.java","lineNumber":84,"sourceCode":"    {\n        return ByteSourceInverse.getOptionalSignedFixedLength(accessor, comparableBytes, 2);\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        short s;\n\n        try\n        {\n            s = Short.parseShort(source);\n        }\n        catch (Exception e)\n        {\n            throw new MarshalException(String.format(\"Unable to make short from '%s'\", source), e);\n        }\n\n        return decompose(s);\n    }\n\n    public Term fromJSONObject(Object parsed) throws MarshalException\n    {\n        if (parsed instanceof String || parsed instanceof Number)\n            return new Constants.Value(fromString(String.valueOf(parsed)));\n\n        throw new MarshalException(String.format(\n                \"Expected a short value, but got a %s: %s\", parsed.getClass().getSimpleName(), parsed));\n    }\n\n    @Override\n    public String toJSONString(ByteBuffer buffer, ProtocolVersion protocolVersion)\n    {\n        return Objects.toString(getSerializer().deserialize(buffer), \"\\\"\\\"\");","sourceCodeStart":66,"sourceCodeEnd":102,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/db/marshal/ShortType.java#L66-L102","documentation":"ShortType.fromString parses a CQL text literal into a 16-bit short via Short.parseShort. If the string is empty, non-numeric, or out of the -32768..32767 range, the NumberFormatException/NullPointerException is wrapped in a MarshalException with this message.","triggerScenarios":"Inserting/binding a value like 'abc', '' or '70000' into a smallint column; calling ShortType.fromString directly; fromJSONObject delegating to fromString with a String or Number that does not parse as a short.","commonSituations":"User supplies a decimal-with-fraction (\"1.5\") or a value outside smallint range; locale/formatting code produces '1,234'; empty string from an unset form field.","solutions":["Validate the input matches an integer regex and fits in -32768..32767 before binding.","Catch MarshalException at the statement-construction boundary and surface a field-level validation message.","Use ByteType/IntType instead if the values are not truly smallint-range."],"exampleFix":"// before\nshort s = Short.parseShort(userInput); // throws on '1.5' or '70000'\n// after\nif (!userInput.matches(\"-?\\\\d+\") || Integer.parseInt(userInput) < Short.MIN_VALUE || Integer.parseInt(userInput) > Short.MAX_VALUE)\n    throw new IllegalArgumentException(\"not a smallint: \" + userInput);\nshort s = Short.parseShort(userInput);","handlingStrategy":"validation","validationCode":"boolean ok = s != null && s.matches(\"-?\\\\d+\"); if (ok) { int v = Integer.parseInt(s); ok = v >= Short.MIN_VALUE && v <= Short.MAX_VALUE; }","typeGuard":null,"tryCatchPattern":"try { ShortType.instance.fromString(s); } catch (MarshalException e) { /* show field-level error: e.getMessage() */ }","preventionTips":["Validate numeric strings and range before binding smallint values","Strip whitespace/locale separators from user input","Catch MarshalException at statement-construction boundaries"],"tags":["cassandra","parsing","numeric","marshal"],"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-14T16:17:12.679Z"}