{"record":{"id":"cb41040e5a0502c3","repo":"prestodb/presto","slug":"invalid-cast-argument-cb4104","errorCode":"INVALID_CAST_ARGUMENT","errorMessage":"Cannot cast value to IPPREFIX: ","messagePattern":"Cannot cast value to IPPREFIX: ","errorType":"error_code","errorClass":"PrestoException","httpStatus":null,"severity":"error","filePath":"presto-main-base/src/main/java/com/facebook/presto/type/IpPrefixOperators.java","lineNumber":140,"sourceCode":"    }\n\n    @ScalarOperator(XX_HASH_64)\n    @SqlType(StandardTypes.BIGINT)\n    public static long xxHash64(@SqlType(StandardTypes.IPPREFIX) Slice value)\n    {\n        return XxHash64.hash(value);\n    }\n\n    @LiteralParameters(\"x\")\n    @ScalarOperator(CAST)\n    @SqlType(StandardTypes.IPPREFIX)\n    public static Slice castFromVarcharToIpPrefix(@SqlType(\"varchar(x)\") Slice slice)\n    {\n        byte[] address;\n        int subnetSize;\n        String string = slice.toStringUtf8();\n        if (!string.contains(\"/\")) {\n            throw new PrestoException(INVALID_CAST_ARGUMENT, \"Cannot cast value to IPPREFIX: \" + slice.toStringUtf8());\n        }\n        String[] parts = string.split(\"/\");\n        try {\n            address = InetAddresses.forString(parts[0]).getAddress();\n        }\n        catch (IllegalArgumentException e) {\n            throw new PrestoException(INVALID_CAST_ARGUMENT, \"Cannot cast value to IPPREFIX: \" + slice.toStringUtf8());\n        }\n        subnetSize = Integer.parseInt(parts[1]);\n\n        byte[] bytes = new byte[IPPREFIX.getFixedSize()];\n        if (address.length == 4) {\n            if (subnetSize < 0 || 32 < subnetSize) {\n                throw new PrestoException(INVALID_CAST_ARGUMENT, \"Cannot cast value to IPPREFIX: \" + slice.toStringUtf8());\n            }\n\n            for (int i = 0; i < 4; i++) {\n                address[3 - i] &= -0x1 << min(max((32 - subnetSize) - 8 * i, 0), 8);","sourceCodeStart":122,"sourceCodeEnd":158,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-main-base/src/main/java/com/facebook/presto/type/IpPrefixOperators.java#L122-L158","documentation":"Cast error in castFromVarcharToIpPrefix: the input text is not a valid IPPREFIX literal — either it lacks the required '/' subnet suffix, or the address/subnet portion failed parsing. The original string is appended; the faulty input is the varchar being cast to IPPREFIX.","triggerScenarios":"Thrown at presto-main-base/src/main/java/com/facebook/presto/type/IpPrefixOperators.java:140 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Use CIDR notation like '10.0.0.0/8' or '2001:db8::/32'","Ensure the subnet prefix length is within range for the address family","Validate the string format before casting"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"55bb57d202de3b926896fa966c2c4a44c779634e","analyzedAt":"2026-09-04T12:50:26.162Z","contentChangedAt":"2026-09-04T12:50:26.162Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}