prestodb/presto · error · PrestoException
GENERIC_INTERNAL_ERROR
GENERIC_INTERNAL_ERROR
Error message
Invalid InetAddress length:
What it means
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.
Source
Thrown at presto-main-base/src/main/java/com/facebook/presto/type/IpPrefixOperators.java:177
}
bytes[10] = (byte) 0xff;
bytes[11] = (byte) 0xff;
arraycopy(address, 0, bytes, 12, 4);
bytes[IPPREFIX.getFixedSize() - 1] = (byte) subnetSize;
}
else if (address.length == 16) {
if (subnetSize < 0 || 128 < subnetSize) {
throw new PrestoException(INVALID_CAST_ARGUMENT, "Cannot cast value to IPPREFIX: " + slice.toStringUtf8());
}
for (int i = 0; i < 16; i++) {
address[15 - i] &= (byte) -0x1 << min(max((128 - subnetSize) - 8 * i, 0), 8);
}
arraycopy(address, 0, bytes, 0, 16);
bytes[IPPREFIX.getFixedSize() - 1] = (byte) subnetSize;
}
else {
throw new PrestoException(GENERIC_INTERNAL_ERROR, "Invalid InetAddress length: " + address.length);
}
return wrappedBuffer(bytes);
}
@ScalarOperator(CAST)
@SqlType(StandardTypes.VARCHAR)
public static Slice castFromIpPrefixToVarchar(@SqlType(StandardTypes.IPPREFIX) Slice slice)
{
try {
String addrString = InetAddresses.toAddrString(InetAddress.getByAddress(slice.getBytes(0, 2 * Long.BYTES)));
String prefixString = Integer.toString(slice.getByte(2 * Long.BYTES) & 0xff);
return utf8Slice(addrString + "/" + prefixString);
}
catch (UnknownHostException e) {
throw new PrestoException(INVALID_CAST_ARGUMENT, "Invalid IP address binary length: " + slice.length(), e);
}
}View on GitHub (pinned to 55bb57d202)
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
Defensive patterns
Strategy: try-catch
Try / catch
// In custom engine/plugin code invoking the cast operator:
try {
Slice prefix = IpPrefixOperators.castFromVarcharToIpPrefix(input);
} catch (PrestoException e) {
if (e.getErrorCode().getCode() == StandardErrorCode.GENERIC_INTERNAL_ERROR.toErrorCode().getCode()) {
// log and report bug; not a user-input problem
}
throw e;
} Prevention
- Run a stock JDK; avoid custom InetAddress providers
- Treat this as an engine bug and file an issue with a repro
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.
Related errors
- GENERIC_INTERNAL_ERROR
- GENERIC_INTERNAL_ERROR
- FUNCTION_IMPLEMENTATION_ERROR
- GENERIC_INTERNAL_ERROR
- GENERIC_INTERNAL_ERROR
AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04).
Data as JSON: /api/errors/11afa2996ac9e36c.
Report an issue: GitHub.