{"record":{"id":"0958b0b991d66a3b","repo":"prestodb/presto","slug":"value-d-is-less-than-min-short","errorCode":null,"errorMessage":"Value %d is less than MIN_SHORT","messagePattern":"Value (.+?) is less than MIN_SHORT","errorType":"exception","errorClass":"GenericInternalException","httpStatus":null,"severity":"error","filePath":"presto-common/src/main/java/com/facebook/presto/common/type/SmallintType.java","lineNumber":149,"sourceCode":"    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    {\n        return getClass().hashCode();\n    }\n","sourceCodeStart":131,"sourceCodeEnd":167,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-common/src/main/java/com/facebook/presto/common/type/SmallintType.java#L131-L167","documentation":"The underflow counterpart of writeLong validation in SmallintType: values below Short.MIN_VALUE (-32768) throw GenericInternalException \"Value %d is less than MIN_SHORT\". It prevents negative out-of-range values from being truncated when written to SMALLINT blocks.","triggerScenarios":"Calling SmallintType.writeLong(blockBuilder, value) with value < -32768, e.g. writing a negative BIGINT/INTEGER value into a SMALLINT block.","commonSituations":"Downcasting wider integer columns to SMALLINT in connector writers; negative computed values (deltas, offsets) exceeding smallint lower bound.","solutions":["Range-check and clamp values to [-32768, 32767] before writing.","Cast explicitly to SMALLINT via SQL cast so standard cast semantics apply.","Change the column type to INTEGER/BIGINT to accommodate the value range."],"exampleFix":"// before\nsmallintType.writeLong(blockBuilder, negativeValue);\n// after\nsmallintType.writeLong(blockBuilder, Math.max(Short.MIN_VALUE, Math.min(Short.MAX_VALUE, negativeValue)));","handlingStrategy":"validation","validationCode":"if (value < Short.MIN_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":["Clamp negative values to Short.MIN_VALUE when saturation is intended.","Verify producer ranges match SMALLINT schema (especially deltas/offsets that can go negative).","Prefer INTEGER/BIGINT columns when values legitimately exceed 16 bits."],"tags":["range-check","underflow","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"}