{"record":{"id":"392e095025c0bbf5","repo":"prestodb/presto","slug":"value-d-exceeds-max-short","errorCode":null,"errorMessage":"Value %d exceeds MAX_SHORT","messagePattern":"Value (.+?) exceeds MAX_SHORT","errorType":"exception","errorClass":"GenericInternalException","httpStatus":null,"severity":"error","filePath":"presto-common/src/main/java/com/facebook/presto/common/type/SmallintType.java","lineNumber":146,"sourceCode":"    }\n\n    @Override\n    public long getLong(Block block, int position)\n    {\n        return (long) block.getShort(position);\n    }\n\n    @Override\n    public long getLongUnchecked(UncheckedBlock block, int internalPosition)\n    {\n        return (long) block.getShortUnchecked(internalPosition);\n    }\n\n    @Override\n    public void writeLong(BlockBuilder blockBuilder, long value)\n    {\n        if (value > Short.MAX_VALUE) {\n            throw new GenericInternalException(format(\"Value %d exceeds MAX_SHORT\", value));\n        }\n        else if (value < Short.MIN_VALUE) {\n            throw new GenericInternalException(format(\"Value %d is less than MIN_SHORT\", value));\n        }\n\n        blockBuilder.writeShort((int) value).closeEntry();\n    }\n\n    @Override\n    @SuppressWarnings(\"EqualsWhichDoesntCheckParameterClass\")\n    public boolean equals(Object other)\n    {\n        return other == SMALLINT;\n    }\n\n    @Override\n    public int hashCode()\n    {","sourceCodeStart":128,"sourceCodeEnd":164,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-common/src/main/java/com/facebook/presto/common/type/SmallintType.java#L128-L164","documentation":"SmallintType.writeLong validates that the long value fits into a 16-bit signed short. Values greater than Short.MAX_VALUE (32767) throw GenericInternalException \"Value %d exceeds MAX_SHORT\". It guards the block writer from silently truncating out-of-range values into SMALLINT storage.","triggerScenarios":"Calling SmallintType.writeLong(blockBuilder, value) with value > 32767, e.g. writing an INTEGER/BIGINT column value into a SMALLINT block without casting.","commonSituations":"Connector writers mapping wider integer types to SMALLINT columns; UDFs emitting values beyond smallint range; table schema changed to SMALLINT while producers still emit larger values.","solutions":["Clamp or range-check the value before writing: if (v > 32767 || v < -32768) handle overflow.","Cast to SMALLINT in SQL so the engine performs defined cast semantics (with error or saturate per config).","Widen the target column to INTEGER/BIGINT if larger values are legitimate."],"exampleFix":"// before\nsmallintType.writeLong(blockBuilder, bigValue);\n// after\nif (bigValue > Short.MAX_VALUE) throw new IllegalArgumentException(...);\nsmallintType.writeLong(blockBuilder, bigValue);","handlingStrategy":"validation","validationCode":"if (value > Short.MAX_VALUE) { /* clamp or widen column type */ }","typeGuard":"boolean fitsSmallint(long v) { return v >= Short.MIN_VALUE && v <= Short.MAX_VALUE; }","tryCatchPattern":"try { smallintType.writeLong(blockBuilder, value); } catch (GenericInternalException e) { /* widen to IntegerType/BigIntegerType or clamp */ }","preventionTips":["Range-check longs against SMALLINT bounds before writing.","Match writer type to declared column type; don't downcast silently.","Use explicit SQL CAST to SMALLINT so defined overflow semantics apply."],"tags":["range-check","overflow","smallint"],"backgroundTag":"integer-overflow-range","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"}