prestodb/presto · error · IllegalArgumentException

code is negative

Error message

code is negative

What it means

WarningCode is a JSON/Thrift serializable pair of (code, name) used to identify warnings. Its @JsonCreator constructor throws IllegalArgumentException("code is negative") when the code property deserialized from JSON (or passed programmatically) is negative.

Source

Thrown at presto-spi/src/main/java/com/facebook/presto/spi/WarningCode.java:39

import java.util.Objects;

import static java.util.Objects.requireNonNull;

@ThriftStruct
public class WarningCode
{
    private final int code;
    private final String name;

    @ThriftConstructor
    @JsonCreator
    public WarningCode(
            @JsonProperty("code") int code,
            @JsonProperty("name") String name)
    {
        if (code < 0) {
            throw new IllegalArgumentException("code is negative");
        }
        this.code = code;
        this.name = requireNonNull(name, "name is null");
    }

    @ThriftField(1)
    @JsonProperty
    public int getCode()
    {
        return code;
    }

    @ThriftField(2)
    @JsonProperty
    public String getName()
    {
        return name;
    }

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Fix the producer to emit non-negative warning codes
  2. Validate/normalize the code before deserialization (e.g. mask or reject at the deserialization boundary)
  3. Update stored/cached warning definitions that contain negative codes

Example fix

// before
WarningCode code = CODEC.fromJson(json); // code: -5
// after
JsonNode node = mapper.readTree(json);
if (node.get("code").intValue() < 0) { node.get("code").... } // sanitize or reject before decoding
Defensive patterns

Strategy: validation

Validate before calling

if (code < 0) throw new IllegalArgumentException("warning code must be non-negative: " + code);

Prevention

When it happens

Trigger: Deserializing JSON like {"code": -1, "name": "x"} into WarningCode, or constructing WarningCode programmatically with a negative code.

Common situations: Older/foreign producers emitting signed error codes in warning payloads; int overflow in a producer turning a large code negative; hand-written JSON test fixtures.

Related errors


AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04). Data as JSON: /api/errors/292223218daf4160. Report an issue: GitHub.