{"record":{"id":"9f8ff95c0ffd92ad","repo":"apache/seatunnel","slug":"long-value-is-out-of-range","errorCode":null,"errorMessage":"Long value is out of range","messagePattern":"Long value is out of range","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"seatunnel-connectors-v2/connector-amazondocumentdb/src/main/java/org/apache/seatunnel/connectors/seatunnel/amazondocumentdb/serialize/DocumentDBItemDeserializer.java","lineNumber":150,"sourceCode":"                || (value.isDecimal128() && value.asDecimal128().getValue().isNaN());\n    }\n\n    private static int checkedInteger(BsonValue value, int minimum, int maximum) {\n        long number = value.asNumber().longValue();\n        if (number < minimum || number > maximum) {\n            throw new IllegalArgumentException(\"Integer value is out of range\");\n        }\n        return (int) number;\n    }\n\n    private static long checkedLong(BsonValue value) {\n        if (value.isInt32() || value.isInt64()) {\n            return value.asNumber().longValue();\n        }\n        if (value.isDouble()) {\n            double number = value.asNumber().doubleValue();\n            if (number < Long.MIN_VALUE || number > Long.MAX_VALUE) {\n                throw new IllegalArgumentException(\"Long value is out of range\");\n            }\n            return value.asNumber().longValue();\n        }\n        throw new IllegalArgumentException(\"Value is not a supported long\");\n    }\n\n    /**\n     * Applies the configured scale and rejects precision overflow instead of silently emitting\n     * {@code null}, which would make malformed source data indistinguishable from BSON null.\n     */\n    private static BigDecimal convertDecimal(DecimalType type, BsonValue value) {\n        Decimal128 decimal128 = value.asDecimal128().decimal128Value();\n        if (!decimal128.isFinite()) {\n            throw new IllegalArgumentException(\"Infinite Decimal128 values are not supported\");\n        }\n        BigDecimal decimal =\n                decimal128.bigDecimalValue().setScale(type.getScale(), RoundingMode.HALF_UP);\n        if (decimal.precision() > type.getPrecision()) {","sourceCodeStart":132,"sourceCodeEnd":168,"githubUrl":"https://github.com/apache/seatunnel/blob/cf67b549a7a6c35fa0beb12d83c62892427ea919/seatunnel-connectors-v2/connector-amazondocumentdb/src/main/java/org/apache/seatunnel/connectors/seatunnel/amazondocumentdb/serialize/DocumentDBItemDeserializer.java#L132-L168","documentation":"DocumentDBItemDeserializer.checkedLong converts a BSON number to long and throws IllegalArgumentException when a double value exceeds the representable Long range (below -2^63 or above 2^63-1, including infinities). This avoids undefined casts and silent data corruption for BIGINT columns.","triggerScenarios":"A BSON double field mapped to SeaTunnel BIGINT holds a value larger than Long.MAX_VALUE (e.g. 1e30) or smaller than Long.MIN_VALUE.","commonSituations":"Scientific/computed values stored as doubles cast to bigint in the schema; a field changed from small magnitudes to huge values upstream; NaN/Infinity doubles entering numeric columns.","solutions":["Change the target column to DOUBLE/DECIMAL type instead of bigint for such large values.","Clean or clamp the source data so values fit in long range.","Add a match query to exclude documents with out-of-range doubles."],"exampleFix":"// before\n{\"name\": \"measure\", \"type\": \"bigint\"}   // double 1e30\n// after\n{\"name\": \"measure\", \"type\": \"double\"}","handlingStrategy":"validation","validationCode":"if (bsonValue.isDouble()) {\n    double d = bsonValue.asNumber().doubleValue();\n    if (d < Long.MIN_VALUE || d > Long.MAX_VALUE || Double.isNaN(d) || Double.isInfinite(d)) {\n        throw new IllegalArgumentException(\"double does not fit bigint column: \" + d);\n    }\n}","typeGuard":null,"tryCatchPattern":"try {\n    long v = checkedLong(bsonValue);\n} catch (IllegalArgumentException e) {\n    log.error(\"Cannot read value as long\", e);\n}","preventionTips":["Use DOUBLE/DECIMAL columns for magnitudes beyond 9.2e18.","Reject or sanitize NaN/Infinity at write time upstream.","Keep schema declarations synced with real data ranges via periodic data profiling."],"tags":["serialization","type-conversion","numeric-overflow"],"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-14T11:17:12.474Z"}