{"record":{"id":"6129eb10065851d6","repo":"apache/seatunnel","slug":"short-overflow","errorCode":null,"errorMessage":"short overflow","messagePattern":"short overflow","errorType":"exception","errorClass":"ArithmeticException","httpStatus":null,"severity":"error","filePath":"seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/utils/ObjectUtils.java","lineNumber":40,"sourceCode":"\npublic class ObjectUtils {\n    /**\n     * Returns a number {@code Object} whose value is {@code (number + augend)}, Note: This method\n     * will throw {@link ArithmeticException} if number overflows.\n     */\n    public static Object plus(Object number, int augend) throws ArithmeticException {\n        if (number instanceof Byte) {\n            // Byte and Short are promoted to int before addition; check their own ranges\n            // before narrowing the result back to the original type.\n            int result = Math.addExact((Byte) number, augend);\n            if (result < Byte.MIN_VALUE || result > Byte.MAX_VALUE) {\n                throw new ArithmeticException(\"byte overflow\");\n            }\n            return (byte) result;\n        } else if (number instanceof Short) {\n            int result = Math.addExact((Short) number, augend);\n            if (result < Short.MIN_VALUE || result > Short.MAX_VALUE) {\n                throw new ArithmeticException(\"short overflow\");\n            }\n            return (short) result;\n        } else if (number instanceof Integer) {\n            return Math.addExact((Integer) number, augend);\n        } else if (number instanceof Long) {\n            return Math.addExact((Long) number, augend);\n        } else if (number instanceof Float) {\n            return ((Float) number) + augend;\n        } else if (number instanceof Double) {\n            return ((Double) number) + augend;\n        } else if (number instanceof BigInteger) {\n            return ((BigInteger) number).add(BigInteger.valueOf(augend));\n        } else if (number instanceof BigDecimal) {\n            return ((BigDecimal) number).add(BigDecimal.valueOf(augend));\n        } else {\n            throw new UnsupportedOperationException(\n                    String.format(\n                            \"Unsupported type %s for numeric plus.\",","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/apache/seatunnel/blob/cf67b549a7a6c35fa0beb12d83c62892427ea919/seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/utils/ObjectUtils.java#L22-L58","documentation":"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.","triggerScenarios":"Calling ObjectUtils.plus(number, augend) where number is a java.lang.Short and number + augend falls outside [-32768, 32767].","commonSituations":"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.","solutions":["Widen the column/field type to Integer or Long (or Decimal) so the sum fits, and re-run the job.","Catch ArithmeticException around ObjectUtils.plus and handle overflow (e.g. switch to Long arithmetic).","Pre-check the operands in your transform: if ((short)s + augend > Short.MAX_VALUE || (short)s + augend < Short.MIN_VALUE) use a wider type."],"exampleFix":"// before\nshort total = (short) ObjectUtils.plus(shortValue, 1000); // throws on overflow\n// after\nlong total = (long) shortValue + 1000; // widen before arithmetic to avoid overflow","handlingStrategy":"try-catch","validationCode":"// pre-check before plus()\nint result = shortValue + augend;\nif (result < Short.MIN_VALUE || result > Short.MAX_VALUE) {\n    throw new IllegalArgumentException(\"sum exceeds short range: \" + result);\n}","typeGuard":"boolean fitsShort(int v) { return v >= Short.MIN_VALUE && v <= Short.MAX_VALUE; }","tryCatchPattern":"try {\n    Object sum = ObjectUtils.plus(number, augend);\n} catch (ArithmeticException e) {\n    // fall back to wider type arithmetic\n    Object sum = ((Number) number).longValue() + ((Number) augend).longValue();\n}","preventionTips":["Prefer Integer/Long columns for fields that will be aggregated.","Range-check operands before short arithmetic.","Write unit tests for boundary values Short.MAX_VALUE and Short.MIN_VALUE."],"tags":["arithmetic","overflow","jdbc"],"backgroundTag":"value-out-of-range","analyzedSha":"cf67b549a7a6c35fa0beb12d83c62892427ea919","analyzedAt":"2026-09-10T21:44:55.265Z","contentChangedAt":"2026-09-10T21:44:55.265Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}