{"record":{"id":"2bc5a3cee533bfe3","repo":"apache/cassandra","slug":"unable-to-make-long-for-time-from-s","errorCode":null,"errorMessage":"Unable to make long (for time) from: '%s'","messagePattern":"Unable to make long \\(for time\\) from: '(.+?)'","errorType":"validation","errorClass":"MarshalException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/serializers/TimeSerializer.java","lineNumber":56,"sourceCode":"    {\n        return value == null ? ByteBufferUtil.EMPTY_BYTE_BUFFER : ByteBufferUtil.bytes(value);\n    }\n\n    public static Long timeStringToLong(String source) throws MarshalException\n    {\n        // nano since start of day, raw\n        if (timePattern.matcher(source).matches())\n        {\n            try\n            {\n                long result = Long.parseLong(source);\n                if (result < 0 || result >= TimeUnit.DAYS.toNanos(1))\n                    throw new NumberFormatException(\"Input long out of bounds: \" + source);\n                return result;\n            }\n            catch (NumberFormatException e)\n            {\n                throw new MarshalException(String.format(\"Unable to make long (for time) from: '%s'\", source), e);\n            }\n        }\n\n        // Last chance, attempt to parse as time string\n        try\n        {\n            return parseTimeStrictly(source);\n        }\n        catch (IllegalArgumentException e1)\n        {\n            throw new MarshalException(String.format(\"(TimeType) Unable to coerce '%s' to a formatted time (long)\", source), e1);\n        }\n    }\n\n    public <V> void validate(V value, ValueAccessor<V> accessor) throws MarshalException\n    {\n        if (accessor.size(value) != 8)\n            throw new MarshalException(String.format(\"Expected 8 byte long for time (%d)\", accessor.size(value)));","sourceCodeStart":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/serializers/TimeSerializer.java#L38-L74","documentation":"TimeSerializer.timeStringToLong first attempts to parse the input as a plain long nanosecond-of-day value. If it is numeric but outside [0, 86399999999] (one day of nanos), or otherwise not a valid long, it throws NumberFormatException which is wrapped into this MarshalException. CQL 'time' values are nanoseconds since midnight stored as an 8-byte long.","triggerScenarios":"Inserting a quoted numeric string like '86400000000000' (exactly one day, out of bounds) or '-1' into a time column; passing '12345678901234567890' which overflows long.","commonSituations":"Confusing milliseconds with nanoseconds (a millis-since-midnight value can be in range but wrong; an epoch-millis value like 1725872400000 exceeds the day bound); off-by-one at the day boundary; unit confusion from other languages' time types.","solutions":["Supply nanoseconds since midnight within [0, 86399999999], e.g. '64989000000000' for 05:03:09","Or use the hh:mm:ss[.fff] time string form, which is parsed by parseTimeStrictly instead","Convert millis to nanos explicitly: TimeUnit.MILLISECONDS.toNanos(millisOfDay)","Pre-check: long n = Long.parseLong(s); assert n >= 0 && n < TimeUnit.DAYS.toNanos(1);"],"exampleFix":"// before\nsession.execute(\"INSERT INTO t (tm) VALUES (?)\", \"86400000000000\"); // 1 day, out of bounds\n// after\nsession.execute(\"INSERT INTO t (tm) VALUES (?)\", \"86399999999999\"); // 23:59:59.999999999","handlingStrategy":"validation","validationCode":"long n;\ntry { n = Long.parseLong(input); } catch (NumberFormatException e) { throw new IllegalArgumentException(\"not a time long\"); }\nif (n < 0 || n >= TimeUnit.DAYS.toNanos(1)) throw new IllegalArgumentException(\"time nanos out of [0, 86399999999]: \" + input);","typeGuard":"boolean isValidTimeNanos(String s) {\n  try { long n = Long.parseLong(s); return n >= 0 && n < TimeUnit.DAYS.toNanos(1); }\n  catch (NumberFormatException e) { return false; }\n}","tryCatchPattern":"try {\n  long nanos = TimeSerializer.timeStringToLong(input);\n} catch (MarshalException e) {\n  throw new BadRequestException(\"time must be nanos since midnight (0..86399999999) or HH:MM:SS[.fff]\");\n}","preventionTips":["Be explicit about units: CQL time is nanoseconds, not millis","Clamp derived values to less than one day before insert","Prefer sending LocalTime objects via driver codecs","Add range assertions in the persistence layer"],"tags":["cassandra","serialization","time","value-out-of-range"],"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"}