prestodb/presto · error · IllegalArgumentException
Invalid VARCHAR length {length}
Error message
Invalid VARCHAR length {length} What it means
AbstractVarcharType's package-private constructor validates that the VARCHAR length is non-negative before creating the type, throwing IllegalArgumentException for negative lengths. VARCHAR types in Presto carry a maximum length; only createVarcharType with length >= 0 (or unbounded VARCHAR) is valid.
Source
Thrown at presto-common/src/main/java/com/facebook/presto/common/type/AbstractVarcharType.java:38
import io.airlift.slice.Slice;
import io.airlift.slice.Slices;
import java.util.Objects;
public class AbstractVarcharType
extends AbstractVariableWidthType
{
public static final int UNBOUNDED_LENGTH = Integer.MAX_VALUE;
public static final int MAX_LENGTH = Integer.MAX_VALUE - 1;
private final int length;
AbstractVarcharType(int length, TypeSignature typeSignature)
{
super(typeSignature, Slice.class);
if (length < 0) {
throw new IllegalArgumentException("Invalid VARCHAR length " + length);
}
this.length = length;
}
@Deprecated
public int getLength()
{
return length;
}
public int getLengthSafe()
{
if (isUnbounded()) {
throw new IllegalStateException("Cannot get size of unbounded VARCHAR.");
}
return length;
}
View on GitHub (pinned to 55bb57d202)
Solutions
- Pass VARCHAR_LENGTH (unbounded) or a non-negative length to createVarcharType; use createUnboundedVarcharType for unbounded
- Treat sentinel values like -1 from metadata as unbounded and map them to unbounded VARCHAR before constructing
- Validate parsed length values (n >= 0) before type construction
- Clamp/fix length arithmetic that can underflow
Example fix
// before
VarcharType type = VarcharType.createVarcharType(metadataLength); // -1 sentinel
// after
VarcharType type = metadataLength < 0
? VarcharType.createUnboundedVarcharType()
: VarcharType.createVarcharType(metadataLength); Defensive patterns
Strategy: validation
Validate before calling
if (length < 0) {
throw new IllegalArgumentException("VARCHAR length must be >= 0, got " + length);
}
VarcharType t = VarcharType.createVarcharType(length); Type guard
boolean isValidVarcharLength(int length) { return length >= 0; } Try / catch
try { type = VarcharType.createVarcharType(len); } catch (IllegalArgumentException e) { type = VarcharType.createUnboundedVarcharType(); } Prevention
- Map metadata sentinel values (-1, 0 for unbounded conventions) to createUnboundedVarcharType
- Validate lengths parsed from DDL/config before constructing types
- Avoid length arithmetic that can underflow to negative
When it happens
Trigger: Calling createVarcharType(length) with a negative length, e.g. from unbounded metadata, a length parsed from a bad DDL/type signature, or an int underflow when computing lengths.
Common situations: Connector metadata returning -1 or another sentinel for 'unbounded' length; parsing VARCHAR(n) from config where n is missing/negative; arithmetic on lengths that overflows to negative.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- Expected VarcharType but got {type.getClass().getName()}
- Expected exactly one parameter for VARCHAR
- VARCHAR length must be a number
- Invalid day-time interval:
- Invalid year-month interval:
AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04).
Data as JSON: /api/errors/bb1a3ad6dcaee389.
Report an issue: GitHub.