{"record":{"id":"a86538a4ac30bb86","repo":"prestodb/presto","slug":"invalid-cast-argument-a86538","errorCode":"INVALID_CAST_ARGUMENT","errorMessage":"Cannot cast value to IPADDRESS: ","messagePattern":"Cannot cast value to IPADDRESS: ","errorType":"error_code","errorClass":"PrestoException","httpStatus":null,"severity":"error","filePath":"presto-main-base/src/main/java/com/facebook/presto/type/IpAddressOperators.java","lineNumber":133,"sourceCode":"\n    @ScalarOperator(XX_HASH_64)\n    @SqlType(StandardTypes.BIGINT)\n    public static long xxHash64(@SqlType(StandardTypes.IPADDRESS) Slice value)\n    {\n        return XxHash64.hash(value);\n    }\n\n    @LiteralParameters(\"x\")\n    @ScalarOperator(CAST)\n    @SqlType(StandardTypes.IPADDRESS)\n    public static Slice castFromVarcharToIpAddress(@SqlType(\"varchar(x)\") Slice slice)\n    {\n        byte[] address;\n        try {\n            address = InetAddresses.forString(slice.toStringUtf8()).getAddress();\n        }\n        catch (IllegalArgumentException e) {\n            throw new PrestoException(INVALID_CAST_ARGUMENT, \"Cannot cast value to IPADDRESS: \" + slice.toStringUtf8());\n        }\n\n        byte[] bytes;\n        if (address.length == 4) {\n            bytes = new byte[16];\n            bytes[10] = (byte) 0xff;\n            bytes[11] = (byte) 0xff;\n            arraycopy(address, 0, bytes, 12, 4);\n        }\n        else if (address.length == 16) {\n            bytes = address;\n        }\n        else {\n            throw new PrestoException(GENERIC_INTERNAL_ERROR, \"Invalid InetAddress length: \" + address.length);\n        }\n\n        return wrappedBuffer(bytes);\n    }","sourceCodeStart":115,"sourceCodeEnd":151,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-main-base/src/main/java/com/facebook/presto/type/IpAddressOperators.java#L115-L151","documentation":"Cast error in castFromVarcharToIpAddress: Guava's InetAddresses.forString rejected the input text as not a valid IP literal (bad formatting or unexpected components). The original text is appended; the faulty input is the varchar being cast to IPADDRESS.","triggerScenarios":"Thrown at presto-main-base/src/main/java/com/facebook/presto/type/IpAddressOperators.java:133 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Use canonical IPv4 or IPv6 literals, e.g. '10.0.0.1' or '::1'","Trim whitespace and remove port/suffix notation before casting","Validate candidate values with a regexp before the cast"],"exampleFix":null,"handlingStrategy":"try-catch","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"}