{"record":{"id":"dbb881c1990a14b2","repo":"apache/cassandra","slug":"input-date-s-is-greater-than-max-supported-date","errorCode":null,"errorMessage":"Input date %s is greater than max supported date %s","messagePattern":"Input date (.+?) is greater than max supported date (.+?)","errorType":"validation","errorClass":"MarshalException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/serializers/SimpleDateSerializer.java","lineNumber":77,"sourceCode":"\n    public static int dateStringToDays(String source) throws MarshalException\n    {\n        // Raw day value in unsigned int form, epoch @ 2^31\n        if (rawPattern.matcher(source).matches())\n        {\n            return parseRaw(source);\n        }\n\n        // Attempt to parse as date string\n        try\n        {\n            LocalDate parsed = formatter.parse(source, LocalDate::from);\n            long millis = parsed.atStartOfDay(UTC).toInstant().toEpochMilli();\n            if (millis < minSupportedDateMillis)\n                throw new MarshalException(String.format(\"Input date %s is less than min supported date %s\", source,\n                        ZonedDateTime.ofInstant(Instant.ofEpochMilli(minSupportedDateMillis), UTC).toString()));\n            if (millis > maxSupportedDateMillis)\n                throw new MarshalException(String.format(\"Input date %s is greater than max supported date %s\", source,\n                        ZonedDateTime.ofInstant(Instant.ofEpochMilli(maxSupportedDateMillis), UTC).toString()));\n\n            return timeInMillisToDay(millis);\n        }\n        catch (DateTimeParseException| ArithmeticException e1)\n        {\n            throw new MarshalException(String.format(\"Unable to coerce '%s' to a formatted date (long)\", source), e1);\n        }\n    }\n\n    private static int parseRaw(String source) {\n        try\n        {\n            long result = Long.parseLong(source);\n\n            if (result < 0 || result > maxSupportedDays)\n                throw new NumberFormatException(\"Input out of bounds: \" + source);\n","sourceCodeStart":59,"sourceCodeEnd":95,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/serializers/SimpleDateSerializer.java#L59-L95","documentation":"SimpleDateSerializer encodes CQL 'date' values as an unsigned int of days since epoch offset by Integer.MIN_VALUE. dateStringToDays parses an ISO-8601 date string (e.g. 2011-02-03 or +5877642-06-15) to epoch millis and rejects values outside the supported range [-5877641-06-23, +5877642-06-15]. This error means the input date parsed fine but its epoch millis exceed maxSupportedDateMillis, i.e. the date is later than Cassandra's max representable date.","triggerScenarios":"Calling dateStringToDays (or inserting into a date column via CQL) with an ISO date string whose instant is after the maximum supported date (~+5877642-06-15); e.g. '9999-12-31' is fine but extreme far-future dates beyond year 5877642 overflow.","commonSituations":"Data migrated from systems allowing wider date ranges; user-supplied date strings passed straight into a date column; generated test data with extreme future dates; confusion between date (day-resolution, limited range) and timestamp types.","solutions":["Use a date within the supported range -5877641-06-23 through +5877642-06-15","If a far-future date is needed, store it as text or as a timestamp/bigint column instead of date","Validate the input year before inserting (e.g. reject years > 5877642)","Insert the raw unsigned-int day encoding via timeInMillisToDay semantics if you truly need an out-of-range logical date"],"exampleFix":"// before\nINSERT INTO events (id, day) VALUES (1, '9999999-01-01');\n// after\nINSERT INTO events (id, day) VALUES (1, '2026-09-09');","handlingStrategy":"validation","validationCode":"LocalDate d = LocalDate.parse(input, DateTimeFormatter.ISO_LOCAL_DATE);\nlong millis = d.atStartOfDay(ZoneOffset.UTC).toInstant().toEpochMilli();\nif (millis > SimpleDateSerializer.maxSupportedDateMillis) throw new IllegalArgumentException(\"date out of range: \" + input);","typeGuard":"boolean isValidCqlDate(String s) {\n  try { LocalDate.parse(s, DateTimeFormatter.ISO_LOCAL_DATE); return true; }\n  catch (DateTimeParseException e) { return false; }\n}","tryCatchPattern":"try {\n  int days = SimpleDateSerializer.dateStringToDays(input);\n} catch (MarshalException e) {\n  log.error(\"Invalid date value {}: {}\", input, e.getMessage());\n  throw new BadRequestException(\"date must be within -5877641-06-23..+5877642-06-15\");\n}","preventionTips":["Restrict user input with an HTML date picker constrained to the supported range","Validate dates at the application edge before CQL insert","Prefer passing typed LocalDate objects through a driver codec rather than strings","Document the date type's limited range for consumers of your schema"],"tags":["cassandra","serialization","date","value-out-of-range"],"backgroundTag":"value-out-of-range","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}