{"record":{"id":"d7b9049b507ee83c","repo":"apache/cassandra","slug":"s-is-not-a-valid-cidr-string","errorCode":null,"errorMessage":"%s is not a valid CIDR String","messagePattern":"(.+?) is not a valid CIDR String","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/CIDR.java","lineNumber":62,"sourceCode":"    {\n        if (netMask > maxNetMaskAllowed(ipAddress))\n            throw new IllegalArgumentException(\"Invalid netmask \" + netMask + \" for IP \" + ipAddress.getHostAddress());\n\n        Pair<InetAddress, InetAddress> ipRange = calcIpRangeOfCidr(ipAddress, netMask);\n        this.startIpAddress = ipRange.left();\n        this.endIpAddress = ipRange.right();\n        this.netMask = netMask;\n    }\n\n    /**\n     * Generates a CIDR from given string\n     * @param cidrStr CIDR as string\n     */\n    public static CIDR getInstance(String cidrStr)\n    {\n        if (cidrStr == null || cidrStr.isEmpty())\n        {\n            throw new IllegalArgumentException(String.format(\"%s is not a valid CIDR String\", cidrStr));\n        }\n\n        String[] parts = cidrStr.split(\"/\");\n        if (parts.length != 2)\n        {\n            throw new IllegalArgumentException(String.format(\"%s is not a valid CIDR String\", cidrStr));\n        }\n\n        short netMask = Short.parseShort(parts[1]);\n\n        InetAddress ipAddress;\n        try\n        {\n            ipAddress = InetAddress.getByName(parts[0]);\n            if (ipAddress instanceof Inet4Address && parts[0].contains(\":\") && parts[0].contains(\".\"))\n            {\n                // Input string is in IPv4 mapped IPv6 format. InetAddress converted it to IPv4\n                // So adjust the net mask accordingly","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/CIDR.java#L44-L80","documentation":"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 '').","triggerScenarios":"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.","commonSituations":"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.","solutions":["Provide a non-null, non-empty CIDR string such as '10.0.0.0/8' before calling CIDR.getInstance","Check the configuration source (cassandra.yaml, system property) that supplied the value and set it properly","Guard the call: skip creating the CIDR object when the input is null or empty"],"exampleFix":"// before\nCIDR cidr = CIDR.getInstance(config.getCidr()); // config.getCidr() == null\n// after\nString cidrStr = config.getCidr();\nCIDR cidr = (cidrStr != null && !cidrStr.isEmpty()) ? CIDR.getInstance(cidrStr) : null;","handlingStrategy":"validation","validationCode":"if (cidrStr == null || cidrStr.isEmpty()) throw new IllegalArgumentException(\"CIDR string required\");\nCIDR cidr = CIDR.getInstance(cidrStr);","typeGuard":"boolean isValidCidrInput(String s) { return s != null && !s.isEmpty(); }","tryCatchPattern":"try { CIDR cidr = CIDR.getInstance(cidrStr); } catch (IllegalArgumentException e) { log.error(\"Invalid CIDR config: {}\", cidrStr, e); }","preventionTips":["Validate configured CIDR values at startup before use","Never pass nullable config fields straight into getInstance","Use a schema/config validator that requires non-empty cidr fields"],"tags":["cassandra","cql","input-validation","null-argument"],"backgroundTag":"invalid-argument-value","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}