{"record":{"id":"19fa7710832a87e6","repo":"apache/cassandra","slug":"expected-a-string-representation-of-an-inet-value","errorCode":null,"errorMessage":"Expected a string representation of an inet value, but got a %s: %s","messagePattern":"Expected a string representation of an inet value, but got a (.+?): (.+?)","errorType":"validation","errorClass":"MarshalException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/db/marshal/InetAddressType.java","lineNumber":85,"sourceCode":"        }\n        catch (Exception e)\n        {\n            throw new MarshalException(String.format(\"Unable to make inet address from '%s'\", source), e);\n        }\n\n        return decompose(address);\n    }\n\n    @Override\n    public Term fromJSONObject(Object parsed) throws MarshalException\n    {\n        try\n        {\n            return new Constants.Value(InetAddressType.instance.fromString((String) parsed));\n        }\n        catch (ClassCastException exc)\n        {\n            throw new MarshalException(String.format(\n                    \"Expected a string representation of an inet value, but got a %s: %s\", parsed.getClass().getSimpleName(), parsed));\n        }\n    }\n\n    private String toString(InetAddress inet)\n    {\n        return inet != null ? inet.getHostAddress() : \"\";\n    }\n\n    @Override\n    public String toJSONString(ByteBuffer buffer, ProtocolVersion protocolVersion)\n    {\n        return '\"' + toString(getSerializer().deserialize(buffer)) + '\"';\n    }\n\n    public CQL3Type asCQL3Type()\n    {\n        return CQL3Type.Native.INET;","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/db/marshal/InetAddressType.java#L67-L103","documentation":"InetAddressType.fromJSONObject() expects the parsed JSON value to be a String representation of an inet address and casts it before calling fromString. When the value is not a String (Boolean, Number, Map, List), the cast fails with ClassCastException, which is converted to this MarshalException. Cassandra requires a textual IP representation for inet JSON input.","triggerScenarios":"Calling InetAddressType.instance.fromJSONObject(parsed, protocolVersion) where parsed is a non-String JSON value, e.g. {\"ip\": 12345} or {\"ip\": true}; the (String) cast throws ClassCastException caught and rethrown as MarshalException.","commonSituations":"JSON payloads emitting raw integers/booleans for inet columns; schema mismatches where an int column became inet (or vice versa); hand-written migration scripts feeding wrong JSON types.","solutions":["Pass the IP as a JSON string: {\"ip\": \"10.0.0.1\"}","Fix the producer to serialize inet fields as strings","Convert non-string values explicitly (String.valueOf) only when semantically valid","Catch MarshalException around fromJSONObject and validate JSON field types before insert"],"exampleFix":"// before\n{\"ip\": 3232235777}\n// after\n{\"ip\": \"192.168.1.1\"}","handlingStrategy":"validation","validationCode":"if (!(parsed instanceof String))\n    throw new IllegalArgumentException(\"inet JSON value must be a string, got: \" + parsed.getClass().getSimpleName());","typeGuard":"static boolean isInetJson(Object v) { return v instanceof String && isValidInet((String) v); }","tryCatchPattern":"try { InetAddressType.instance.fromJSONObject(parsed, pv); } catch (MarshalException e) { /* reject record: inet field must be a string */ }","preventionTips":["Serialize inet columns as JSON strings only","Validate JSON payload types against schema before insert","Convert legacy numeric IP encodings to strings upstream","Test JSON ingestion with mixed-type payloads to catch drift"],"tags":["cassandra","marshalling","json","inet"],"backgroundTag":"type-mismatch","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"}