{"record":{"id":"ac959d18ee8c0bff","repo":"apache/cassandra","slug":"time-values-must-be-enclosed-by-single-quotes","errorCode":null,"errorMessage":"time values must be enclosed by single quotes","messagePattern":"time values must be enclosed by single quotes","errorType":"exception","errorClass":"InvalidTypeException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/functions/types/TypeCodec.java","lineNumber":1900,"sourceCode":"        {\n            super(DataType.time());\n        }\n\n        @Override\n        public int serializedSize()\n        {\n            // matching behavior of TimeType, which is not declared as fixed length\n            return VARIABLE_LENGTH;\n        }\n\n        @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);","sourceCodeStart":1882,"sourceCodeEnd":1918,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/functions/types/TypeCodec.java#L1882-L1918","documentation":"Thrown by TypeCodec.TimeCodec.parse(String) because CQL time literals must be enclosed in single quotes even when given as a plain long (nanoseconds since midnight). The codec enforces quoting unconditionally to disambiguate time literals from other numeric tokens; an unquoted value is rejected immediately with this message before any parsing.","triggerScenarios":"Calling TimeCodec.parse() with unquoted input such as 34200000000000 as the raw string \"34200000000000\" or \"08:30:00\" — anything where ParseUtils.isQuoted(value) is false. Also triggered by literals built without quotes in string concatenation.","commonSituations":"Building query literals by hand and forgetting to quote time values (unlike int/bigint, quotes are mandatory); passing results of Long.toString(nanos) straight to parse; copying cqlsh output that displays unquoted values.","solutions":["Wrap the value in single quotes: parse(\"'34200000000000'\") or parse(\"'08:30:00.000'\").","Use ParseUtils.quote(value) when constructing literals programmatically.","Pass a java.lang.Long nanoseconds value via bound statements/codecs (format/serialize) instead of string parsing.","Catch InvalidTypeException and auto-quote with a helper before retrying parse."],"exampleFix":"// before\nLong t = TypeCodec.time().parse(\"08:30:00\");\n// after\nLong t = TypeCodec.time().parse(\"'08:30:00'\");","handlingStrategy":"validation","validationCode":"static String quoteCqlTime(String v) {\n    return \"'\" + v + \"'\";\n}\nstatic boolean isQuotedCqlTime(String v) {\n    return v != null && v.length() >= 2 && v.charAt(0) == '\\'' && v.charAt(v.length() - 1) == '\\'';\n}","typeGuard":null,"tryCatchPattern":"try {\n    Long t = TypeCodec.time().parse(literal);\n} catch (InvalidTypeException e) {\n    // auto-quote and retry once\n    t = TypeCodec.time().parse(\"'\" + literal + \"'\");\n}","preventionTips":["Always single-quote time literals, even numeric ones — unlike int/bigint.","Use ParseUtils.quote() when generating literals programmatically.","Prefer binding Long nanoseconds via bound statements.","Document the quoting rule wherever time literals are built."],"tags":["cassandra","codec","time","quoting","invalid-type-exception"],"backgroundTag":"invalid-argument-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"}