apache/cassandra · error · IllegalArgumentException

%s is not a valid CIDR String

Error message

%s is not a valid CIDR String

What it means

CIDR.getInstance() parses a string like '10.0.0.0/8' into a CIDR object. It throws IllegalArgumentException when the input string is null or empty, since no CIDR can be constructed from it. The thrown message includes the offending value (which will be 'null' or '').

Source

Thrown at src/java/org/apache/cassandra/cql3/CIDR.java:62

    {
        if (netMask > maxNetMaskAllowed(ipAddress))
            throw new IllegalArgumentException("Invalid netmask " + netMask + " for IP " + ipAddress.getHostAddress());

        Pair<InetAddress, InetAddress> ipRange = calcIpRangeOfCidr(ipAddress, netMask);
        this.startIpAddress = ipRange.left();
        this.endIpAddress = ipRange.right();
        this.netMask = netMask;
    }

    /**
     * Generates a CIDR from given string
     * @param cidrStr CIDR as string
     */
    public static CIDR getInstance(String cidrStr)
    {
        if (cidrStr == null || cidrStr.isEmpty())
        {
            throw new IllegalArgumentException(String.format("%s is not a valid CIDR String", cidrStr));
        }

        String[] parts = cidrStr.split("/");
        if (parts.length != 2)
        {
            throw new IllegalArgumentException(String.format("%s is not a valid CIDR String", cidrStr));
        }

        short netMask = Short.parseShort(parts[1]);

        InetAddress ipAddress;
        try
        {
            ipAddress = InetAddress.getByName(parts[0]);
            if (ipAddress instanceof Inet4Address && parts[0].contains(":") && parts[0].contains("."))
            {
                // Input string is in IPv4 mapped IPv6 format. InetAddress converted it to IPv4
                // So adjust the net mask accordingly

View on GitHub (pinned to 88fd0f6a0e)

Solutions

  1. Provide a non-null, non-empty CIDR string such as '10.0.0.0/8' before calling CIDR.getInstance
  2. Check the configuration source (cassandra.yaml, system property) that supplied the value and set it properly
  3. Guard the call: skip creating the CIDR object when the input is null or empty

Example fix

// before
CIDR cidr = CIDR.getInstance(config.getCidr()); // config.getCidr() == null
// after
String cidrStr = config.getCidr();
CIDR cidr = (cidrStr != null && !cidrStr.isEmpty()) ? CIDR.getInstance(cidrStr) : null;
Defensive patterns

Strategy: validation

Validate before calling

if (cidrStr == null || cidrStr.isEmpty()) throw new IllegalArgumentException("CIDR string required");
CIDR cidr = CIDR.getInstance(cidrStr);

Type guard

boolean isValidCidrInput(String s) { return s != null && !s.isEmpty(); }

Try / catch

try { CIDR cidr = CIDR.getInstance(cidrStr); } catch (IllegalArgumentException e) { log.error("Invalid CIDR config: {}", cidrStr, e); }

Prevention

When it happens

Trigger: Calling CIDR.getInstance(null) or CIDR.getInstance("") directly, or via configuration that resolves a network/CIDR setting (e.g. network_authorizer CIDR configuration) where the configured value is blank.

Common situations: cassandra.yaml or role-based network authorization config has an empty cidr field; code passes an unset system property or environment variable into getInstance; a null value read from a config file.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


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