apache/cassandra · error · ParseException
Unable to parse the date:
Error message
Unable to parse the date:
What it means
This java.text.ParseException is thrown by ParseUtils.parseDate(String, String, Locale) when none of the candidate date patterns (or the supplied pattern) can fully parse the input string, or the parser does not consume the entire string. It signals the string is not a valid date in any expected format.
Source
Thrown at src/java/org/apache/cassandra/cql3/functions/types/ParseUtils.java:337
// so we need to transform the string first
// so that accepted patterns are correctly handled,
// such as Z for UTC, or "+00:00" instead of "+0000".
// Note: we cannot use the X letter in the pattern
// because it has been introduced in Java 7.
str = str.replaceAll("(\\+|\\-)(\\d\\d):(\\d\\d)$", "$1$2$3");
str = str.replaceAll("Z$", "+0000");
ParsePosition pos = new ParsePosition(0);
for (String parsePattern : iso8601Patterns)
{
parser.applyPattern(parsePattern);
pos.setIndex(0);
Date date = parser.parse(str, pos);
if (date != null && pos.getIndex() == str.length())
{
return date;
}
}
throw new ParseException("Unable to parse the date: " + str, -1);
}
/**
* Parse the given string as a date, using the supplied date pattern.
*
* <p>This method is adapted from Apache Commons {@code DateUtils.parseStrictly()} method (that is
* used Cassandra side to parse date strings)..
*
* @throws ParseException If the given string cannot be parsed with the given pattern.
* @see <a href="https://cassandra.apache.org/doc/cql3/CQL-2.2.html#usingtimestamps">'Working with
* timestamps' section of CQL specification</a>
*/
static Date parseDate(String str, String pattern) throws ParseException
{
SimpleDateFormat parser = new SimpleDateFormat();
parser.setLenient(false);
// set a default timezone for patterns that do not provide one
parser.setTimeZone(TimeZone.getTimeZone("UTC"));View on GitHub (pinned to 88fd0f6a0e)
Solutions
- Correct the date string to match one of the supported patterns (e.g. yyyy-MM-dd or the pattern argument you passed)
- Pre-validate the string with a strict regex or DateTimeFormatter.ISO_LOCAL_DATE before calling parseDate
- Catch ParseException and fall back to trying alternate patterns or report the expected format to the user
Example fix
// before
ParseUtils.parseDate("2026/09/09", "yyyy-MM-dd", Locale.US)
// after
ParseUtils.parseDate("2026-09-09", "yyyy-MM-dd", Locale.US) Defensive patterns
Strategy: try-catch
Validate before calling
static boolean looksLikeDate(String s, java.time.format.DateTimeFormatter f) {
try { java.time.LocalDate.parse(s.trim(), f); return true; } catch (java.time.format.DateTimeParseException e) { return false; }
} Try / catch
try { Date d = ParseUtils.parseDate(str, pattern, locale); } catch (ParseException e) { log.warn("Unparseable date '{}' for pattern {}", str, pattern, e); /* fallback or rethrow as user-facing validation error */ } Prevention
- Trim and normalize input (strip whitespace/BOM) before parsing
- Validate with java.time DateTimeFormatter first — it gives better error messages than SimpleDateFormat
- Standardize on one canonical date format (ISO yyyy-MM-dd) at API boundaries
- Specify an explicit Locale to avoid month-name mismatches
When it happens
Trigger: Binding a date string like '2026-13-45' or '01/02/2026x' where ParseUtils.parseDate is called with candidate patterns and every SimpleDateFormat.parse either fails or leaves unparsed trailing characters (pos.getIndex() != str.length()).
Common situations: US vs EU day/month order mismatches ('13/05/2026'); two-digit years resolving unexpectedly; stray whitespace or trailing characters; loading timestamps exported in a format not among the tried patterns.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- Cannot parse date value from "%s"
- can't interpret %r as a date with format %s or as int
- Invalid value for system property: expected integer value bu
- Invalid value for system property: expected long value but g
- Invalid value for system property: expected floating point v
AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10).
Data as JSON: /api/errors/6b18a07d7848991e.
Report an issue: GitHub.