apache/cassandra · error · InvalidTypeException
Cannot parse date value from "%s"
Error message
Cannot parse date value from "%s"
What it means
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.
Source
Thrown at src/java/org/apache/cassandra/cql3/functions/types/TypeCodec.java:1821
@Override
public LocalDate parse(String value)
{
if (value == null || value.isEmpty() || value.equalsIgnoreCase("NULL")) return null;
// single quotes are optional for long literals, mandatory for date patterns
// strip enclosing single quotes, if any
if (ParseUtils.isQuoted(value)) value = ParseUtils.unquote(value);
if (ParseUtils.isLongLiteral(value))
{
long unsigned;
try
{
unsigned = Long.parseLong(value);
}
catch (NumberFormatException e)
{
throw new InvalidTypeException(
String.format("Cannot parse date value from \"%s\"", value), e);
}
try
{
int days = CodecUtils.fromCqlDateToDaysSinceEpoch(unsigned);
return LocalDate.fromDaysSinceEpoch(days);
}
catch (IllegalArgumentException e)
{
throw new InvalidTypeException(
String.format("Cannot parse date value from \"%s\"", value), e);
}
}
try
{
Date date = ParseUtils.parseDate(value, pattern);
return LocalDate.fromMillisSinceEpoch(date.getTime());View on GitHub (pinned to 88fd0f6a0e)
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.
Example fix
// before
LocalDate d = TypeCodec.date().parse("'2024-01-15x'");
// after
LocalDate d = TypeCodec.date().parse("'2024-01-15'"); Defensive patterns
Strategy: validation
Validate before calling
static boolean isDateLiteral(String s) {
String t = s == null ? "" : s.trim();
if (t.matches("\\d+")) { try { Long.parseLong(t); return true; } catch (NumberFormatException e) { return false; } }
try { java.time.LocalDate.parse(t); return true; } catch (DateTimeParseException e) { return false; }
} Try / catch
try {
LocalDate d = TypeCodec.date().parse(literal);
} catch (InvalidTypeException e) {
log.warn("Bad date literal: {}", literal);
throw new IllegalArgumentException("Expected yyyy-MM-dd or a valid date number");
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Cannot parse 32-bits int value from "%s"
- Cannot parse timestamp value from "%s"
- Cannot parse time value from "%s"
- Invalid 32-bits integer value, expecting 4 bytes but got %d
- time values must be enclosed by single quotes
AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10).
Data as JSON: /api/errors/9be61180dc5ddb10.
Report an issue: GitHub.