{"record":{"id":"4a63d2a731c78375","repo":"apache/cassandra","slug":"unable-to-coerce-s-to-a-formatted-date-long","errorCode":null,"errorMessage":"Unable to coerce '%s' to a formatted date (long)","messagePattern":"Unable to coerce '(.+?)' to a formatted date \\(long\\)","errorType":"validation","errorClass":"MarshalException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/serializers/SimpleDateSerializer.java","lineNumber":84,"sourceCode":"        }\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\n            // Shift > epoch days into negative portion of Integer result for byte order comparability\n            if (result >= Integer.MAX_VALUE)\n                result -= byteOrderShift;\n\n            return (int) result;\n        }\n        catch (NumberFormatException | DateTimeParseException e)","sourceCodeStart":66,"sourceCodeEnd":102,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/serializers/SimpleDateSerializer.java#L66-L102","documentation":"dateStringToDays first tries to interpret the input as an ISO-8601 date string using DateTimeFormatter; if parsing throws DateTimeParseException or the epoch-milli arithmetic overflows (ArithmeticException), it wraps the failure in this MarshalException. It means the string is not a valid formatted date for the 'date' type.","triggerScenarios":"Passing a string that is not ISO_LOCAL_DATE format (e.g. '03/02/2011', 'Feb 3 2011', epoch millis '1345', empty string) to dateStringToDays or inserting such a literal into a date column without quoting/encoding.","commonSituations":"Locale-formatted dates pasted from UI code; sending a long (raw encoding or epoch millis) where an ISO string is expected; trailing whitespace or timezone suffixes like '2020-01-01T00:00:00Z'; old clients using pre-2.2 date formats.","solutions":["Supply the date as ISO-8601 local date format: yyyy-MM-dd (optionally with a +/- sign and extended year for extreme dates)","Quote the literal in CQL so it is parsed by the serializer rather than treated as an invalid token: '2011-02-03'","If you already have the raw unsigned-int encoding, insert it as a quoted integer string (the serializer accepts it via parseRaw)","Pre-validate with LocalDate.parse(input, DateTimeFormatter.ISO_LOCAL_DATE)"],"exampleFix":"// before\nsession.execute(\"INSERT INTO t (d) VALUES (?)\", \"02/03/2011\");\n// after\nsession.execute(\"INSERT INTO t (d) VALUES (?)\", \"2011-02-03\");","handlingStrategy":"validation","validationCode":"try { LocalDate.parse(input, DateTimeFormatter.ISO_LOCAL_DATE); } catch (DateTimeParseException e) { throw new IllegalArgumentException(\"expected yyyy-MM-dd: \" + input); }","typeGuard":"static boolean isIsoDate(String s) {\n  return s != null && ISO_LOCAL_DATE.matcher(s).matches(); // e.g. ^[+-]?\\d{4,}-\\d{2}-\\d{2}$\n}","tryCatchPattern":"try {\n  session.execute(insert.bindString(\"d\", input));\n} catch (InvalidQueryException | MarshalException e) {\n  if (e.getMessage().contains(\"formatted date\")) throw new BadRequestException(\"use ISO yyyy-MM-dd for date columns\");\n  throw e;\n}","preventionTips":["Always format dates with DateTimeFormatter.ISO_LOCAL_DATE before sending","Quote date literals in CQL strings","Normalize input: trim and strip time/timezone components","Prefer object binding (LocalDate codec) over string literals"],"tags":["cassandra","serialization","date","invalid-date-format"],"backgroundTag":"invalid-date-format","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}