{"record":{"id":"df307dad6c1b9317","repo":"elastic/elasticsearch","slug":"time-value-cannot-store-values-greater-than-106751","errorCode":null,"errorMessage":"time value cannot store values greater than 106751 days","messagePattern":"time value cannot store values greater than 106751 days","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"libs/core/src/main/java/org/elasticsearch/core/TimeValue.java","lineNumber":89,"sourceCode":"        return new TimeValue(seconds, TimeUnit.SECONDS);\n    }\n\n    public static TimeValue timeValueMinutes(long minutes) {\n        if (minutes == 1) {\n            // common value, no need to allocate each time\n            return ONE_MINUTE;\n        }\n        return new TimeValue(minutes, TimeUnit.MINUTES);\n    }\n\n    public static TimeValue timeValueHours(long hours) {\n        return new TimeValue(hours, TimeUnit.HOURS);\n    }\n\n    public static TimeValue timeValueDays(long days) {\n        // 106751.9 days is Long.MAX_VALUE nanoseconds, so we cannot store 106752 days\n        if (days > 106751) {\n            throw new IllegalArgumentException(\"time value cannot store values greater than 106751 days\");\n        }\n        return new TimeValue(days, TimeUnit.DAYS);\n    }\n\n    /**\n     * @return the {@link TimeValue} object that has the least duration.\n     */\n    public static TimeValue min(TimeValue time1, TimeValue time2) {\n        return time1.compareTo(time2) < 0 ? time1 : time2;\n    }\n\n    /**\n     * @return the unit used for the this time value, see {@link #duration()}\n     */\n    public TimeUnit timeUnit() {\n        return timeUnit;\n    }\n","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/libs/core/src/main/java/org/elasticsearch/core/TimeValue.java#L71-L107","documentation":"Thrown by TimeValue.timeValueDays when the input exceeds 106751 days. That limit is not arbitrary: 106751.9 days is Long.MAX_VALUE expressed in nanoseconds, and TimeValue internally stores durations convertible to nanoseconds, so any larger value would overflow. The check prevents silent overflow that would otherwise produce a nonsense (possibly negative) duration.","triggerScenarios":"Configuring an index retention or lifecycle interval in days with an absurdly large value (e.g. `365000`). Constructing a TimeValue from a computed `days` long that overflowed. Confusing units (passing milliseconds into a days field).","commonSituations":"Typo adding extra zeros to a retention period. Settings meant to be infinite that should use -1 instead of a huge number. Unit confusion in conversion code.","solutions":["Use -1 (TimeValue.MINUS_ONE) to represent infinite/unlimited durations rather than a huge day count.","Reduce the value to a realistic bound (< 106751 days, i.e. ~292 years).","Double-check the unit: ensure you are not passing milliseconds or seconds into a days parameter.","Validate input range before constructing: `if (days > 106751) throw ...`."],"exampleFix":"// before\nTimeValue retention = TimeValue.timeValueDays(1_000_000);\n// after\nTimeValue retention = TimeValue.MINUS_ONE; // or a realistic value\nTimeValue retention = TimeValue.timeValueDays(365);","handlingStrategy":"validation","validationCode":"static TimeValue safeDays(long days) {\n    if (days > 106751) {\n        throw new IllegalArgumentException(\"Days value \" + days + \" exceeds 106751; use -1 for unlimited.\");\n    }\n    return TimeValue.timeValueDays(days);\n}","typeGuard":"static boolean isStorableDaysValue(long days) {\n    return days <= 106751;\n}","tryCatchPattern":"try {\n    TimeValue tv = TimeValue.timeValueDays(days);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().contains(\"106751\")) {\n        // use -1 to represent unlimited, or cap at the maximum storable value\n        return TimeValue.MINUS_ONE;\n    }\n    throw e;\n}","preventionTips":["Use -1 (TimeValue.MINUS_ONE) for unlimited durations instead of huge day counts.","Validate ranges at the configuration boundary before constructing TimeValue.","Beware unit confusion: confirm you are passing days, not milliseconds or seconds."],"tags":["core","time-value","overflow","validation","configuration"],"backgroundTag":null,"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}