{"record":{"id":"bccc72e36318fa57","repo":"elastic/elasticsearch","slug":"value-text-is-out-of-range-for-an-integer","errorCode":null,"errorMessage":"Value [${text}] is out of range for an integer","messagePattern":"Value \\[(.+?)\\] is out of range for an integer","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"libs/x-content/src/main/java/org/elasticsearch/xcontent/support/AbstractXContentParser.java","lineNumber":165,"sourceCode":"    }\n\n    protected abstract short doShortValue() throws IOException;\n\n    @Override\n    public int intValue() throws IOException {\n        return intValue(DEFAULT_NUMBER_COERCE_POLICY);\n    }\n\n    /**\n     * Parses an {@code int} from its decimal string representation, using the same semantics as the\n     * document-indexing path. The value is first parsed as a {@code double} and then narrowed; values\n     * outside [{@value Integer#MIN_VALUE}, {@value Integer#MAX_VALUE}] throw\n     * {@link IllegalArgumentException}.\n     */\n    public static int parseInt(String text) {\n        double doubleValue = Double.parseDouble(text);\n        if (doubleValue < Integer.MIN_VALUE || doubleValue > Integer.MAX_VALUE) {\n            throw new IllegalArgumentException(\"Value [\" + text + \"] is out of range for an integer\");\n        }\n        return (int) doubleValue;\n    }\n\n    @Override\n    public int intValue(boolean coerce) throws IOException {\n        Token token = currentToken();\n        if (token == Token.VALUE_STRING) {\n            checkCoerceString(coerce, Integer.class);\n            XContentString numericText = optimizedText();\n            checkNumericStringLength(numericText.stringLength());\n            return parseInt(numericText.string());\n        }\n        int result = doIntValue();\n        ensureNumberConversion(coerce, result, Integer.class);\n        return result;\n    }\n","sourceCodeStart":147,"sourceCodeEnd":183,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/libs/x-content/src/main/java/org/elasticsearch/xcontent/support/AbstractXContentParser.java#L147-L183","documentation":"Thrown by AbstractXContentParser.parseInt() when the decimal string representation, parsed as a double, falls outside the int range [-2147483648, 2147483647]. The method parses the string as a double first (to handle scientific notation uniformly) and then range-checks against Integer.MIN_VALUE and Integer.MAX_VALUE before narrowing.","triggerScenarios":"Calling intValue() on a parser whose current value is a numeric string or number exceeding Integer.MAX_VALUE (2147483647) or below Integer.MIN_VALUE (-2147483648). For example, parsing a value of \"3000000000\" as an int.","commonSituations":"Field mapped as integer receiving values that fit only in a long. Timestamps in milliseconds exceeding 2147483647. Large IDs or counters that grew beyond int range. Scientific notation strings (e.g., \"3e9\") that parse to values beyond int range.","solutions":["Ensure the value is within [-2147483648, 2147483647].","Change the field mapping from integer to long if values can exceed the int range.","Validate the value range client-side before submitting.","If the value is a timestamp, use long type from the start."],"exampleFix":"// before — value exceeds int range\n{ \"timestamp_ms\": 3000000000 }\n\n// after — use long mapping and valid value\n{ \"timestamp_ms\": 1690000000000 }","handlingStrategy":"validation","validationCode":"// Before sending, verify the value fits in int range\npublic static void validateIntRange(Object value, String fieldName) {\n    if (value instanceof Number n) {\n        double d = n.doubleValue();\n        if (d < Integer.MIN_VALUE || d > Integer.MAX_VALUE) {\n            throw new IllegalArgumentException(fieldName + \" value \" + n + \" is out of range for int [-2147483648, 2147483647]\");\n        }\n    }\n}","typeGuard":null,"tryCatchPattern":"try {\n    int value = parser.intValue();\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().contains(\"out of range for an integer\")) {\n        throw new BadRequestException(e.getMessage());\n    }\n    throw e;\n}","preventionTips":["Use long field types for values that may exceed Integer.MAX_VALUE (2147483647).","Validate numeric ranges client-side against the field's target type before sending.","Be especially careful with timestamps, counters, and large IDs that can grow beyond int range."],"tags":["parsing","xcontent","numeric","overflow","integer","range"],"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-12T08:17:17.861Z"}