{"record":{"id":"0828a8db3a16b5d2","repo":"apache/cassandra","slug":"cannot-parse-inet-value-from-s","errorCode":null,"errorMessage":"Cannot parse inet value from \"%s\"","messagePattern":"Cannot parse inet value from \"(.+?)\"","errorType":"validation","errorClass":"InvalidTypeException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/functions/types/TypeCodec.java","lineNumber":1507,"sourceCode":"            super(DataType.inet(), InetAddress.class);\n        }\n\n        @Override\n        public InetAddress parse(String value)\n        {\n            if (value == null || value.isEmpty() || value.equalsIgnoreCase(\"NULL\")) return null;\n\n            value = value.trim();\n            if (!ParseUtils.isQuoted(value))\n                throw new InvalidTypeException(\n                String.format(\"inet values must be enclosed in single quotes (\\\"%s\\\")\", value));\n            try\n            {\n                return InetAddress.getByName(value.substring(1, value.length() - 1));\n            }\n            catch (Exception e)\n            {\n                throw new InvalidTypeException(String.format(\"Cannot parse inet value from \\\"%s\\\"\", value));\n            }\n        }\n\n        @Override\n        public String format(InetAddress value)\n        {\n            if (value == null) return \"NULL\";\n            return '\\'' + value.getHostAddress() + '\\'';\n        }\n\n        @Override\n        public ByteBuffer serialize(InetAddress value, ProtocolVersion protocolVersion)\n        {\n            return value == null ? null : ByteBuffer.wrap(value.getAddress());\n        }\n\n        @Override\n        public InetAddress deserialize(ByteBuffer bytes, ProtocolVersion protocolVersion)","sourceCodeStart":1489,"sourceCodeEnd":1525,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/functions/types/TypeCodec.java#L1489-L1525","documentation":"Thrown by InetCodec.parse when the quoted string stripped of its single quotes cannot be resolved to an InetAddress by InetAddress.getByName. The value passed the quoting check but the address text itself is malformed or unresolvable.","triggerScenarios":"Calling InetCodec.parse(\"'not-an-address'\") or with an unresolvable hostname (DNS failure), an invalid IPv4/IPv6 literal like \"'999.1.1.1'\", or a hostname that no longer resolves.","commonSituations":"Typo in a hardcoded IP, stale hostname after DNS changes, IPv6 literals entered with wrong syntax (e.g. missing brackets or zones), or offline environments where hostname resolution fails.","solutions":["Validate the address with InetAddress.getByName in a try/catch before parsing, or use a regex for IPv4/IPv6 literals.","Prefer literal IP addresses over hostnames to avoid DNS dependence.","Use prepared statements with setInet(InetAddress) so the address object is validated at construction.","Catch InvalidTypeException and log the offending value for correction."],"exampleFix":"// before\nInetAddress a = new InetCodec().parse(\"'\" + userInput + \"'\");\n// after\ntry {\n    InetAddress check = InetAddress.getByName(userInput.trim());\n    InetAddress a = new InetCodec().parse(\"'\" + check.getHostAddress() + \"'\");\n} catch (UnknownHostException e) {\n    throw new IllegalArgumentException(\"Invalid inet literal: \" + userInput, e);\n}","handlingStrategy":"validation","validationCode":"boolean isResolvableInet(String s) {\n    String v = s == null ? null : s.trim().replaceAll(\"^'|'$\", \"\");\n    try { if (v != null) InetAddress.getByName(v); return true; }\n    catch (Exception e) { return false; }\n}","typeGuard":null,"tryCatchPattern":"try { InetAddress a = codec.parse(value); }\ncatch (InvalidTypeException e) {\n    throw new IllegalArgumentException(\"Unresolvable or malformed inet: \" + value, e);\n}","preventionTips":["Validate addresses with InetAddress.getByName at input boundaries.","Prefer literal IPs over hostnames to avoid DNS failures.","Use setInet(InetAddress) on bound statements.","Catch and log the offending literal for correction."],"tags":["parsing","inet","dns","type-codec"],"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-17T15:17:12.973Z"}