apache/cassandra · error · InvalidTypeException

Cannot parse inet value from

Error message

Cannot parse inet value from "%s"

What it means

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.

Solutions

  1. Validate the address with InetAddress.getByName in a try/catch before parsing, or use a regex for IPv4/IPv6 literals.
  2. Prefer literal IP addresses over hostnames to avoid DNS dependence.
  3. Use prepared statements with setInet(InetAddress) so the address object is validated at construction.
  4. Catch InvalidTypeException and log the offending value for correction.

Example fix

// before
InetAddress a = new InetCodec().parse("'" + userInput + "'");
// after
try {
    InetAddress check = InetAddress.getByName(userInput.trim());
    InetAddress a = new InetCodec().parse("'" + check.getHostAddress() + "'");
} catch (UnknownHostException e) {
    throw new IllegalArgumentException("Invalid inet literal: " + userInput, e);
}
Defensive patterns

Strategy: validation

Validate before calling

boolean isResolvableInet(String s) {
    String v = s == null ? null : s.trim().replaceAll("^'|'$", "");
    try { if (v != null) InetAddress.getByName(v); return true; }
    catch (Exception e) { return false; }
}

Try / catch

try { InetAddress a = codec.parse(value); }
catch (InvalidTypeException e) {
    throw new IllegalArgumentException("Unresolvable or malformed inet: " + value, e);
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

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


AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10). Data as JSON: /api/errors/0828a8db3a16b5d2. Report an issue: GitHub.

Appendix: source

Thrown at src/java/org/apache/cassandra/cql3/functions/types/TypeCodec.java:1507

            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() + '\'';
        }

        @Override
        public ByteBuffer serialize(InetAddress value, ProtocolVersion protocolVersion)
        {
            return value == null ? null : ByteBuffer.wrap(value.getAddress());
        }

        @Override
        public InetAddress deserialize(ByteBuffer bytes, ProtocolVersion protocolVersion)

View on GitHub (pinned to 88fd0f6a0e)