{"record":{"id":"17aaccfc9bdcb7db","repo":"apache/cassandra","slug":"cannot-parse-timestamp-value-from-s","errorCode":null,"errorMessage":"Cannot parse timestamp value from \"%s\"","messagePattern":"Cannot parse timestamp value from \"(.+?)\"","errorType":"exception","errorClass":"InvalidTypeException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/functions/types/TypeCodec.java","lineNumber":1748,"sourceCode":"            return 8;\n        }\n\n        @Override\n        public Date parse(String value)\n        {\n            if (value == null || value.isEmpty() || value.equalsIgnoreCase(\"NULL\")) return null;\n            // strip enclosing single quotes, if any\n            if (ParseUtils.isQuoted(value)) value = ParseUtils.unquote(value);\n\n            if (ParseUtils.isLongLiteral(value))\n            {\n                try\n                {\n                    return new Date(Long.parseLong(value));\n                }\n                catch (NumberFormatException e)\n                {\n                    throw new InvalidTypeException(\n                    String.format(\"Cannot parse timestamp value from \\\"%s\\\"\", value));\n                }\n            }\n\n            try\n            {\n                return ParseUtils.parseDate(value);\n            }\n            catch (ParseException e)\n            {\n                throw new InvalidTypeException(\n                String.format(\"Cannot parse timestamp value from \\\"%s\\\"\", value));\n            }\n        }\n\n        @Override\n        public String format(Date value)\n        {","sourceCodeStart":1730,"sourceCodeEnd":1766,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/functions/types/TypeCodec.java#L1730-L1766","documentation":"Thrown by TypeCodec.TimestampCodec.parse(String) when the string looks like a numeric long literal (isLongLiteral), but Long.parseLong fails or (conceptually) the numeric form is invalid — i.e. the quoted value overflows a long or is malformed, so it cannot become a Date from epoch millis. The library converts CQL timestamp literals either from epoch milliseconds (long) or from date/time strings; this branch handles the numeric one.","triggerScenarios":"Calling TimestampCodec.parse() with a quoted numeric string that overflows long range (e.g. \"99999999999999999999\") or contains characters that look numeric to isLongLiteral but fail parseLong; parse is reached only when isLongLiteral(value) is true.","commonSituations":"Timestamps copied from other systems in units other than millis (seconds/micros) padded with digits beyond long range; hand-built literals with stray signs or underscores; users typing full-precision timestamps from other languages into cqlsh-style literals.","solutions":["Supply epoch milliseconds that fit in a signed 64-bit long (e.g. 1700000000000).","Drop the quotes/numeric form and use a standard date string like '2024-01-15 10:30:00+0000' instead.","Strip invalid characters (spaces, separators) before parsing.","Catch InvalidTypeException and re-prompt/convert the input with a proper timestamp parser."],"exampleFix":"// before\nDate d = TypeCodec.timestamp().parse(\"'2024-01-15T10:30:00Z'\"); // parsed as long literal branch? no—use proper form\n// after\nDate d = TypeCodec.timestamp().parse(\"'1705314600000'\");\n// or, preferably, a date string:\nDate d2 = TypeCodec.timestamp().parse(\"'2024-01-15 10:30:00+0000'\");","handlingStrategy":"validation","validationCode":"static boolean isValidEpochMillis(String s) {\n    String t = s == null ? \"\" : s.trim();\n    try { long ms = Long.parseLong(t); return ms >= Long.MIN_VALUE; } catch (NumberFormatException e) { return false; }\n}","typeGuard":null,"tryCatchPattern":"try {\n    Date d = TypeCodec.timestamp().parse(literal);\n} catch (InvalidTypeException e) {\n    log.warn(\"Bad timestamp literal: {}\", literal);\n    d = new Date(System.currentTimeMillis()); // or surface a validation error\n}","preventionTips":["Pass Date objects or epoch-millis longs via bound statements instead of parsing strings.","Use accepted formats: epoch millis or 'yyyy-MM-dd HH:mm:ss+0000'.","Avoid timestamps from other systems with non-millisecond units.","Normalize 'T'-separated ISO strings before parsing."],"tags":["cassandra","codec","timestamp","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"}