{"record":{"id":"292223218daf4160","repo":"prestodb/presto","slug":"code-is-negative","errorCode":null,"errorMessage":"code is negative","messagePattern":"code is negative","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"presto-spi/src/main/java/com/facebook/presto/spi/WarningCode.java","lineNumber":39,"sourceCode":"\nimport java.util.Objects;\n\nimport static java.util.Objects.requireNonNull;\n\n@ThriftStruct\npublic class WarningCode\n{\n    private final int code;\n    private final String name;\n\n    @ThriftConstructor\n    @JsonCreator\n    public WarningCode(\n            @JsonProperty(\"code\") int code,\n            @JsonProperty(\"name\") String name)\n    {\n        if (code < 0) {\n            throw new IllegalArgumentException(\"code is negative\");\n        }\n        this.code = code;\n        this.name = requireNonNull(name, \"name is null\");\n    }\n\n    @ThriftField(1)\n    @JsonProperty\n    public int getCode()\n    {\n        return code;\n    }\n\n    @ThriftField(2)\n    @JsonProperty\n    public String getName()\n    {\n        return name;\n    }","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-spi/src/main/java/com/facebook/presto/spi/WarningCode.java#L21-L57","documentation":"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.","triggerScenarios":"Deserializing JSON like {\"code\": -1, \"name\": \"x\"} into WarningCode, or constructing WarningCode programmatically with a negative code.","commonSituations":"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.","solutions":["Fix the producer to emit non-negative warning codes","Validate/normalize the code before deserialization (e.g. mask or reject at the deserialization boundary)","Update stored/cached warning definitions that contain negative codes"],"exampleFix":"// before\nWarningCode code = CODEC.fromJson(json); // code: -5\n// after\nJsonNode node = mapper.readTree(json);\nif (node.get(\"code\").intValue() < 0) { node.get(\"code\").... } // sanitize or reject before decoding","handlingStrategy":"validation","validationCode":"if (code < 0) throw new IllegalArgumentException(\"warning code must be non-negative: \" + code);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate warning payloads at the deserialization boundary","Ensure producers use unsigned/positive code ranges and avoid int overflow"],"tags":["spi","illegal-argument","deserialization","warning-code"],"backgroundTag":"invalid-numeric-value","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"}