apache/cassandra · error · InvalidTypeException
inet values must be enclosed in single quotes
Error message
inet values must be enclosed in single quotes ("%s") What it means
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.
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.
Example fix
// before
InetAddress a = new InetCodec().parse("10.0.0.1");
// after
InetAddress a = new InetCodec().parse("'10.0.0.1'");
// or preferably
InetAddress a = (InetAddress) new InetCodec().format("10.0.0.1") != null
? java.net.InetAddress.getByName("10.0.0.1") : null; Defensive patterns
Strategy: validation
Validate before calling
boolean isQuotedInetLiteral(String s) {
return s != null && ParseUtils.isQuoted(s.trim());
} Try / catch
try { InetAddress a = codec.parse(value); }
catch (InvalidTypeException e) {
// re-quote bare literals and retry once
InetAddress a2 = codec.parse("'" + value.trim() + "'");
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.
Related errors
- Cannot parse inet value from
- Cannot parse 16-bits int value from
- Cannot parse 32-bits float value from
- Cannot parse 8-bits int value from
- A CQL blob string must have an even length (since one byte…
AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10).
Data as JSON: /api/errors/655f52f946419b5a.
Report an issue: GitHub.
Appendix: source
Thrown at src/java/org/apache/cassandra/cql3/functions/types/TypeCodec.java:1499
*/
private static class InetCodec extends TypeCodec<InetAddress>
{
private static final InetCodec instance = new InetCodec();
private InetCodec()
{
super(DataType.inet(), InetAddress.class);
}
@Override
public InetAddress parse(String value)
{
if (value == null || value.isEmpty() || value.equalsIgnoreCase("NULL")) return null;
value = value.trim();
if (!ParseUtils.isQuoted(value))
throw new InvalidTypeException(
String.format("inet values must be enclosed in single quotes (\"%s\")", value));
try
{
return InetAddress.getByName(value.substring(1, value.length() - 1));
}
catch (Exception e)
{
throw new InvalidTypeException(String.format("Cannot parse inet value from \"%s\"", value));
}
}
@Override
public String format(InetAddress value)
{
if (value == null) return "NULL";
return '\'' + value.getHostAddress() + '\'';
}
View on GitHub (pinned to 88fd0f6a0e)