{"record":{"id":"9be61180dc5ddb10","repo":"apache/cassandra","slug":"cannot-parse-date-value-from-s","errorCode":null,"errorMessage":"Cannot parse date value from \"%s\"","messagePattern":"Cannot parse date value from \"(.+?)\"","errorType":"exception","errorClass":"InvalidTypeException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/functions/types/TypeCodec.java","lineNumber":1821,"sourceCode":"        @Override\n        public LocalDate parse(String value)\n        {\n            if (value == null || value.isEmpty() || value.equalsIgnoreCase(\"NULL\")) return null;\n\n            // single quotes are optional for long literals, mandatory for date patterns\n            // strip enclosing single quotes, if any\n            if (ParseUtils.isQuoted(value)) value = ParseUtils.unquote(value);\n\n            if (ParseUtils.isLongLiteral(value))\n            {\n                long unsigned;\n                try\n                {\n                    unsigned = Long.parseLong(value);\n                }\n                catch (NumberFormatException e)\n                {\n                    throw new InvalidTypeException(\n                    String.format(\"Cannot parse date value from \\\"%s\\\"\", value), e);\n                }\n                try\n                {\n                    int days = CodecUtils.fromCqlDateToDaysSinceEpoch(unsigned);\n                    return LocalDate.fromDaysSinceEpoch(days);\n                }\n                catch (IllegalArgumentException e)\n                {\n                    throw new InvalidTypeException(\n                    String.format(\"Cannot parse date value from \\\"%s\\\"\", value), e);\n                }\n            }\n\n            try\n            {\n                Date date = ParseUtils.parseDate(value, pattern);\n                return LocalDate.fromMillisSinceEpoch(date.getTime());","sourceCodeStart":1803,"sourceCodeEnd":1839,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/functions/types/TypeCodec.java#L1803-L1839","documentation":"Thrown by TypeCodec.DateCodec.parse(String) when the value is treated as a numeric long literal for the CQL date type (encoded as unsigned int days-since-epoch) but Long.parseLong fails — the literal contains characters incompatible with a long, or overflows. CQL date literals may be either an unquoted/quoted integer (days since epoch, unsigned encoding) or a 'yyyy-MM-dd' string.","triggerScenarios":"Calling DateCodec.parse() with something like '2024-1-15abc' where isLongLiteral still returns true (e.g. starts with digits) but parseLong throws NumberFormatException; reached only inside the isLongLiteral branch.","commonSituations":"Malformed literals copied from logs; typos like trailing characters or stray whitespace/underscore inside a numeric date; overflowed values far outside the long range; programmatic literals built by string concatenation.","solutions":["Fix the literal to a plain integer (days since epoch in the unsigned-int CQL encoding) or a clean 'yyyy-MM-dd' string.","Trim whitespace and strip any non-digit characters before parsing.","Prefer the readable string form: parse(\"'2024-01-15'\") rather than raw integers.","Catch InvalidTypeException and fall back to constructing com.datastax.driver.core.LocalDate.fromDaysSinceEpoch/fromMillisSinceEpoch directly in code."],"exampleFix":"// before\nLocalDate d = TypeCodec.date().parse(\"'2024-01-15x'\");\n// after\nLocalDate d = TypeCodec.date().parse(\"'2024-01-15'\");","handlingStrategy":"validation","validationCode":"static boolean isDateLiteral(String s) {\n    String t = s == null ? \"\" : s.trim();\n    if (t.matches(\"\\\\d+\")) { try { Long.parseLong(t); return true; } catch (NumberFormatException e) { return false; } }\n    try { java.time.LocalDate.parse(t); return true; } catch (DateTimeParseException e) { return false; }\n}","typeGuard":null,"tryCatchPattern":"try {\n    LocalDate d = TypeCodec.date().parse(literal);\n} catch (InvalidTypeException e) {\n    log.warn(\"Bad date literal: {}\", literal);\n    throw new IllegalArgumentException(\"Expected yyyy-MM-dd or a valid date number\");\n}","preventionTips":["Use the quoted 'yyyy-MM-dd' string form; it is the least error-prone.","Trim literals before parsing.","Avoid building numeric literals via string concatenation.","Bind com.datastax.driver.core.LocalDate objects directly instead of parsing strings."],"tags":["cassandra","codec","date","parsing","invalid-type-exception"],"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"}