apache/seatunnel · error · ArithmeticException

short overflow

Error message

short overflow

What it means

ObjectUtils.plus() throws ArithmeticException("short overflow") when adding a value to a Short exceeds the short numeric range. Java's Math.addExact computes the sum in int, and the method then explicitly checks the result against Short.MIN_VALUE/MAX_VALUE before downcasting, so overflow is detected instead of silently wrapping.

Solutions

  1. Widen the column/field type to Integer or Long (or Decimal) so the sum fits, and re-run the job.
  2. Catch ArithmeticException around ObjectUtils.plus and handle overflow (e.g. switch to Long arithmetic).
  3. Pre-check the operands in your transform: if ((short)s + augend > Short.MAX_VALUE || (short)s + augend < Short.MIN_VALUE) use a wider type.

Example fix

// before
short total = (short) ObjectUtils.plus(shortValue, 1000); // throws on overflow
// after
long total = (long) shortValue + 1000; // widen before arithmetic to avoid overflow
Defensive patterns

Strategy: try-catch

Validate before calling

// pre-check before plus()
int result = shortValue + augend;
if (result < Short.MIN_VALUE || result > Short.MAX_VALUE) {
    throw new IllegalArgumentException("sum exceeds short range: " + result);
}

Type guard

boolean fitsShort(int v) { return v >= Short.MIN_VALUE && v <= Short.MAX_VALUE; }

Try / catch

try {
    Object sum = ObjectUtils.plus(number, augend);
} catch (ArithmeticException e) {
    // fall back to wider type arithmetic
    Object sum = ((Number) number).longValue() + ((Number) augend).longValue();
}

Prevention

When it happens

Trigger: Calling ObjectUtils.plus(number, augend) where number is a java.lang.Short and number + augend falls outside [-32768, 32767].

Common situations: Accumulating counters or sums in a SeaTunnel JDBC pipeline whose column type is SMALLINT (mapped to Short) and the running total grows past the short range; arithmetic transforms applied to short-typed fields.

Understand the failure class

Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.

Related errors


AI-assisted analysis of apache/seatunnel@cf67b549a7 (2026-09-10). Data as JSON: /api/errors/6129eb10065851d6. Report an issue: GitHub.

Appendix: source

Thrown at seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/utils/ObjectUtils.java:40

public class ObjectUtils {
    /**
     * Returns a number {@code Object} whose value is {@code (number + augend)}, Note: This method
     * will throw {@link ArithmeticException} if number overflows.
     */
    public static Object plus(Object number, int augend) throws ArithmeticException {
        if (number instanceof Byte) {
            // Byte and Short are promoted to int before addition; check their own ranges
            // before narrowing the result back to the original type.
            int result = Math.addExact((Byte) number, augend);
            if (result < Byte.MIN_VALUE || result > Byte.MAX_VALUE) {
                throw new ArithmeticException("byte overflow");
            }
            return (byte) result;
        } else if (number instanceof Short) {
            int result = Math.addExact((Short) number, augend);
            if (result < Short.MIN_VALUE || result > Short.MAX_VALUE) {
                throw new ArithmeticException("short overflow");
            }
            return (short) result;
        } else if (number instanceof Integer) {
            return Math.addExact((Integer) number, augend);
        } else if (number instanceof Long) {
            return Math.addExact((Long) number, augend);
        } else if (number instanceof Float) {
            return ((Float) number) + augend;
        } else if (number instanceof Double) {
            return ((Double) number) + augend;
        } else if (number instanceof BigInteger) {
            return ((BigInteger) number).add(BigInteger.valueOf(augend));
        } else if (number instanceof BigDecimal) {
            return ((BigDecimal) number).add(BigDecimal.valueOf(augend));
        } else {
            throw new UnsupportedOperationException(
                    String.format(
                            "Unsupported type %s for numeric plus.",

View on GitHub (pinned to cf67b549a7)