{"record":{"id":"67b5d57fe936c1b4","repo":"apache/dubbo","slug":"not-an-valid-cidr-format","errorCode":null,"errorMessage":"not an valid CIDR format!","messagePattern":"not an valid CIDR format!","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"dubbo-common/src/main/java/org/apache/dubbo/common/utils/CIDRUtils.java","lineNumber":61,"sourceCode":"    private final int prefixLength;\n\n\n    public CIDRUtils(String cidr) throws UnknownHostException {\n\n        this.cidr = cidr;\n\n        /* split CIDR to address and prefix part */\n        if (this.cidr.contains(\"/\")) {\n            int index = this.cidr.indexOf(\"/\");\n            String addressPart = this.cidr.substring(0, index);\n            String networkPart = this.cidr.substring(index + 1);\n\n            inetAddress = InetAddress.getByName(addressPart);\n            prefixLength = Integer.parseInt(networkPart);\n\n            calculate();\n        } else {\n            throw new IllegalArgumentException(\"not an valid CIDR format!\");\n        }\n    }\n\n\n    private void calculate() throws UnknownHostException {\n\n        ByteBuffer maskBuffer;\n        int targetSize;\n        if (inetAddress.getAddress().length == 4) {\n            maskBuffer =\n                    ByteBuffer\n                            .allocate(4)\n                            .putInt(-1);\n            targetSize = 4;\n        } else {\n            maskBuffer = ByteBuffer.allocate(16)\n                    .putLong(-1L)\n                    .putLong(-1L);","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/apache/dubbo/blob/3a3043227f5571d25eb2889de5bca22f2914843b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/CIDRUtils.java#L43-L79","documentation":"Thrown by the CIDRUtils constructor when the input string does not contain a '/' separator. A CIDR block must be 'address/prefix' (e.g. '192.168.0.0/16'); the slash separates the base address from the prefix length. Without it the constructor cannot split the two parts and rejects the input as malformed.","triggerScenarios":"new CIDRUtils(cidr) where cidr.contains(\"/\") is false — e.g. '192.168.1.0', '10.0.0.0', 'localhost'. The constructor only proceeds if the slash is present; any plain IP or hostname string is rejected.","commonSituations":"A trust/allowlist IP filter configured with a bare IP instead of a CIDR (e.g. '192.168.1.0' instead of '192.168.1.0/24'); a config property sourced from an env var or YAML that omits the prefix; copy-paste of an IP where a network range was intended.","solutions":["Add the '/prefix' suffix: for a single host use '/32' (IPv4) or '/128' (IPv6); for a subnet use the correct prefix (e.g. '/24').","Validate the input contains '/' before constructing CIDRUtils.","If a bare IP is legitimately intended (single host), append '/32' (IPv4) explicitly."],"exampleFix":"// before\nnew CIDRUtils(\"192.168.1.0\"); // throws: no slash\n\n// after\nnew CIDRUtils(\"192.168.1.0/24\"); // subnet\nnew CIDRUtils(\"192.168.1.5/32\"); // single host","handlingStrategy":"validation","validationCode":"String cidr = \"...\";\nif (cidr == null || !cidr.contains(\"/\")) {\n    throw new IllegalArgumentException(\"CIDR must be 'address/prefix', e.g. '192.168.0.0/16'\");\n}\nnew CIDRUtils(cidr);","typeGuard":"static boolean isCidrFormat(String s) {\n    return s != null && s.contains(\"/\")\n        && s.indexOf('/') < s.length() - 1;\n}","tryCatchPattern":null,"preventionTips":["Always include the '/prefix' suffix in CIDR config.","For single hosts use '/32' (IPv4) or '/128' (IPv6).","Lint allowlist/filter configs for bare IPs at deploy time."],"tags":["network","cidr","configuration","validation"],"backgroundTag":null,"analyzedSha":"3a3043227f5571d25eb2889de5bca22f2914843b","analyzedAt":"2026-08-14T00:43:19.853Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}