{"record":{"id":"655f52f946419b5a","repo":"apache/cassandra","slug":"inet-values-must-be-enclosed-in-single-quotes-s","errorCode":null,"errorMessage":"inet values must be enclosed in single quotes (\"%s\")","messagePattern":"inet values must be enclosed in single quotes \\(\"(.+?)\"\\)","errorType":"validation","errorClass":"InvalidTypeException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/functions/types/TypeCodec.java","lineNumber":1499,"sourceCode":"     */\n    private static class InetCodec extends TypeCodec<InetAddress>\n    {\n\n        private static final InetCodec instance = new InetCodec();\n\n        private InetCodec()\n        {\n            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","sourceCodeStart":1481,"sourceCodeEnd":1517,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/functions/types/TypeCodec.java#L1481-L1517","documentation":"Thrown by InetCodec.parse when the string value is not enclosed in single quotes, which the CQL literal syntax requires for inet values. The codec trims the input and rejects anything that lacks surrounding single quotes before attempting InetAddress resolution.","triggerScenarios":"Calling InetCodec.parse(String) with an unquoted literal like \"192.168.0.1\" or \"::1\" instead of \"'192.168.0.1'\", typically when parsing CQL literal text or reading string-form protocol payloads.","commonSituations":"Hand-writing CQL literals in scripts or cqlsh-like tools without quotes, building INSERT statements via string concatenation, or feeding output of format() back without re-quoting correctly.","solutions":["Wrap the value in single quotes before parsing: \"'\" + value + \"'\".","Better, use InetCodec.format(value) to produce a correctly quoted literal, or bind via a prepared statement's setInet().","Strip surrounding double quotes or whitespace and re-quote with single quotes if data came from another serialization.","Catch InvalidTypeException and re-quote/retry when the input is known to be a bare address."],"exampleFix":"// before\nInetAddress a = new InetCodec().parse(\"10.0.0.1\");\n// after\nInetAddress a = new InetCodec().parse(\"'10.0.0.1'\");\n// or preferably\nInetAddress a = (InetAddress) new InetCodec().format(\"10.0.0.1\") != null\n    ? java.net.InetAddress.getByName(\"10.0.0.1\") : null;","handlingStrategy":"validation","validationCode":"boolean isQuotedInetLiteral(String s) {\n    return s != null && ParseUtils.isQuoted(s.trim());\n}","typeGuard":null,"tryCatchPattern":"try { InetAddress a = codec.parse(value); }\ncatch (InvalidTypeException e) {\n    // re-quote bare literals and retry once\n    InetAddress a2 = codec.parse(\"'\" + value.trim() + \"'\");\n}","preventionTips":["Always produce literals via codec.format(value), not manual concatenation.","Use prepared statements with setInet to avoid literal syntax entirely.","Trim and normalize user input before parsing.","Remember CQL inet literals require single quotes, not double."],"tags":["parsing","inet","quoting","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"}