{"record":{"id":"9c2814a78fa30a6d","repo":"apache/cassandra","slug":"cannot-parse-time-value-from-s","errorCode":null,"errorMessage":"Cannot parse time value from \"%s\"","messagePattern":"Cannot parse time value from \"(.+?)\"","errorType":"exception","errorClass":"InvalidTypeException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/functions/types/TypeCodec.java","lineNumber":1911,"sourceCode":"        @Override\n        public Long parse(String value)\n        {\n            if (value == null || value.isEmpty() || value.equalsIgnoreCase(\"NULL\")) return null;\n\n            // enclosing single quotes required, even for long literals\n            if (!ParseUtils.isQuoted(value))\n                throw new InvalidTypeException(\"time values must be enclosed by single quotes\");\n            value = value.substring(1, value.length() - 1);\n\n            if (ParseUtils.isLongLiteral(value))\n            {\n                try\n                {\n                    return Long.parseLong(value);\n                }\n                catch (NumberFormatException e)\n                {\n                    throw new InvalidTypeException(\n                    String.format(\"Cannot parse time value from \\\"%s\\\"\", value), e);\n                }\n            }\n\n            try\n            {\n                return ParseUtils.parseTime(value);\n            }\n            catch (ParseException e)\n            {\n                throw new InvalidTypeException(\n                String.format(\"Cannot parse time value from \\\"%s\\\"\", value), e);\n            }\n        }\n\n        @Override\n        public String format(Long value)\n        {","sourceCodeStart":1893,"sourceCodeEnd":1929,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/functions/types/TypeCodec.java#L1893-L1929","documentation":"Thrown by TypeCodec.TimeCodec.parse(String) when the quoted value's inner text looks like a long literal but Long.parseLong fails — e.g. a number out of long range or containing characters that slipped past isLongLiteral. Time values are nanoseconds within one day (0..86399999999999), and this branch converts the quoted numeric form to a java Long.","triggerScenarios":"Calling TimeCodec.parse() with a quoted oversized number like \"'99999999999999999999'\", or a malformed numeric token inside quotes; reached only after the mandatory quoting check and when isLongLiteral(inner) is true.","commonSituations":"Milliseconds/microseconds mistakenly supplied where nanoseconds are expected (unit confusion with overflow guard-rails); concatenated literals with stray characters; generated values exceeding the day range and long-range typos.","solutions":["Supply a valid nanoseconds count within 0..86399999999999, quoted, e.g. \"'30600000000000'\" for 08:30.","Use the string form \"'HH:MM:SS[.fff]'\" instead of a numeric literal.","Clamp/convert units (millis*1_000_000) before parsing and assert the range.","Catch InvalidTypeException and validate the range in code, then construct the Long directly for bound statements."],"exampleFix":"// before\nLong t = TypeCodec.time().parse(\"'99999999999999999999'\");\n// after\nlong nanos = TimeUnit.HOURS.toNanos(8) + TimeUnit.MINUTES.toNanos(30);\nLong t = TypeCodec.time().parse(\"'\" + nanos + \"'\"); // or bind the Long directly","handlingStrategy":"validation","validationCode":"static boolean isValidNanosOfDay(long n) {\n    return n >= 0 && n <= 86_399_999_999_999L;\n}\nstatic boolean isQuotedLong(String s) {\n    if (s == null || s.length() < 3 || s.charAt(0) != '\\'') return false;\n    try { Long.parseLong(s.substring(1, s.length() - 1)); return true; } catch (NumberFormatException e) { return false; }\n}","typeGuard":null,"tryCatchPattern":"try {\n    Long t = TypeCodec.time().parse(literal);\n} catch (InvalidTypeException e) {\n    log.warn(\"Bad time literal: {}\", literal);\n    throw new IllegalArgumentException(\"Expected quoted nanos or HH:MM:SS[.fff]\");\n}","preventionTips":["Confirm units: CQL time is nanoseconds since midnight, not millis/micros.","Validate the 0..86399999999999 range before building literals.","Prefer the 'HH:MM:SS.fff' string form for readability.","Bind Long values directly to statements to skip string parsing."],"tags":["cassandra","codec","time","parsing","invalid-type-exception"],"backgroundTag":"value-out-of-range","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"}