{"record":{"id":"11afa2996ac9e36c","repo":"prestodb/presto","slug":"generic-internal-error-11afa2","errorCode":"GENERIC_INTERNAL_ERROR","errorMessage":"Invalid InetAddress length: ","messagePattern":"Invalid InetAddress length: ","errorType":"error_code","errorClass":"PrestoException","httpStatus":null,"severity":"error","filePath":"presto-main-base/src/main/java/com/facebook/presto/type/IpPrefixOperators.java","lineNumber":177,"sourceCode":"            }\n            bytes[10] = (byte) 0xff;\n            bytes[11] = (byte) 0xff;\n            arraycopy(address, 0, bytes, 12, 4);\n            bytes[IPPREFIX.getFixedSize() - 1] = (byte) subnetSize;\n        }\n        else if (address.length == 16) {\n            if (subnetSize < 0 || 128 < subnetSize) {\n                throw new PrestoException(INVALID_CAST_ARGUMENT, \"Cannot cast value to IPPREFIX: \" + slice.toStringUtf8());\n            }\n\n            for (int i = 0; i < 16; i++) {\n                address[15 - i] &= (byte) -0x1 << min(max((128 - subnetSize) - 8 * i, 0), 8);\n            }\n            arraycopy(address, 0, bytes, 0, 16);\n            bytes[IPPREFIX.getFixedSize() - 1] = (byte) subnetSize;\n        }\n        else {\n            throw new PrestoException(GENERIC_INTERNAL_ERROR, \"Invalid InetAddress length: \" + address.length);\n        }\n\n        return wrappedBuffer(bytes);\n    }\n\n    @ScalarOperator(CAST)\n    @SqlType(StandardTypes.VARCHAR)\n    public static Slice castFromIpPrefixToVarchar(@SqlType(StandardTypes.IPPREFIX) Slice slice)\n    {\n        try {\n            String addrString = InetAddresses.toAddrString(InetAddress.getByAddress(slice.getBytes(0, 2 * Long.BYTES)));\n            String prefixString = Integer.toString(slice.getByte(2 * Long.BYTES) & 0xff);\n            return utf8Slice(addrString + \"/\" + prefixString);\n        }\n        catch (UnknownHostException e) {\n            throw new PrestoException(INVALID_CAST_ARGUMENT, \"Invalid IP address binary length: \" + slice.length(), e);\n        }\n    }","sourceCodeStart":159,"sourceCodeEnd":195,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-main-base/src/main/java/com/facebook/presto/type/IpPrefixOperators.java#L159-L195","documentation":"castFromVarcharToIpPrefix expects the resolved InetAddress to be either 4 bytes (IPv4) or 16 bytes (IPv6). Any other length indicates an unexpected internal state in address parsing, so Presto throws GENERIC_INTERNAL_ERROR. This is a defensive branch, not a user-input validation error.","triggerScenarios":"Calling CAST(varchar AS IPPREFIX) when InetAddress.getAddress() returns a byte array of length other than 4 or 16 — an internal invariant violation in JDK address parsing.","commonSituations":"Extremely rare; typically surfaces only with a patched/non-standard JDK InetAddress implementation or custom code paths feeding unexpected binary forms. Not caused by normal user input.","solutions":["Verify the standard JDK is being used (no custom InetAddress providers)","File a bug with the query and value that triggered it","Work around by pre-parsing with try_cast or explicit IP parsing before the cast"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// In custom engine/plugin code invoking the cast operator:\ntry {\n    Slice prefix = IpPrefixOperators.castFromVarcharToIpPrefix(input);\n} catch (PrestoException e) {\n    if (e.getErrorCode().getCode() == StandardErrorCode.GENERIC_INTERNAL_ERROR.toErrorCode().getCode()) {\n        // log and report bug; not a user-input problem\n    }\n    throw e;\n}","preventionTips":["Run a stock JDK; avoid custom InetAddress providers","Treat this as an engine bug and file an issue with a repro"],"tags":["presto","ipprefix","internal-error","inetaddress"],"backgroundTag":"internal-invariant-violation","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"}