{"record":{"id":"631a638231b1b304","repo":"apache/cassandra","slug":"invalid-null-value-of-timestamp","errorCode":null,"errorMessage":"Invalid null value of timestamp","messagePattern":"Invalid null value of timestamp","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/Attributes.java","lineNumber":92,"sourceCode":"\n    public boolean isTimestampSet()\n    {\n        return timestamp != null;\n    }\n\n    public boolean isTimeToLiveSet()\n    {\n        return timeToLive != null;\n    }\n\n    public long getTimestamp(long now, FunctionContext context) throws InvalidRequestException\n    {\n        if (timestamp == null)\n            return now;\n\n        ByteBuffer tval = timestamp.bindAndGet(context);\n        if (tval == null)\n            throw new InvalidRequestException(\"Invalid null value of timestamp\");\n\n        if (tval == ByteBufferUtil.UNSET_BYTE_BUFFER)\n            return now;\n\n        try\n        {\n            LongType.instance.validate(tval);\n        }\n        catch (MarshalException e)\n        {\n            throw new InvalidRequestException(\"Invalid timestamp value: \" + tval);\n        }\n\n        return LongType.instance.compose(tval);\n    }\n\n    public int getTimeToLive(FunctionContext context, TableMetadata metadata) throws InvalidRequestException\n    {","sourceCodeStart":74,"sourceCodeEnd":110,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/Attributes.java#L74-L110","documentation":"Attributes.getTimestamp resolves the USING TIMESTAMP term of an INSERT/UPDATE; if the bound term evaluates to null (the protocol sent null for the timestamp bind marker), the write has no well-defined timestamp, so Cassandra throws InvalidRequestException. Note an unset (UNSET_BYTE_BUFFER) value is allowed and falls back to 'now'.","triggerScenarios":"Executing INSERT/UPDATE with 'USING TIMESTAMP ?' and supplying null as the bound value of the timestamp parameter (or a JSON bind producing null); timestamp bind marker used but client sends null.","commonSituations":"Driver code passing a null Integer/Long into a bound statement for the timestamp; JSON-based inserts where the timestamp field is null; ORMs serializing missing optional fields as null.","solutions":["Bind a concrete long (e.g. System.currentTimeMillis() * 1000) or use Unset/omit the USING TIMESTAMP clause when the timestamp should be defaulted","Use unset values (Unset.valueOf / unset bound variables) instead of null so the server falls back to 'now'","Guard client-side: check the timestamp parameter for null before executing the statement","If using JSON inserts, drop the [timestamp] column/field rather than sending null"],"exampleFix":"// before\nBoundStatement bs = ps.bind().setLong(0, id).setLong(1, null); // USING TIMESTAMP ?\n// after\nBoundStatement bs = ps.bind().setLong(0, id);\nbs.set(1, System.currentTimeMillis() * 1000L, Long.class); // or omit USING TIMESTAMP","handlingStrategy":"try-catch","validationCode":"if (timestamp == null)\n    throw new IllegalArgumentException(\"USING TIMESTAMP value must not be null; use unset or a concrete long\");","typeGuard":"boolean isValidTimestamp(Long ts) { return ts != null && ts >= 0; }","tryCatchPattern":"try {\n    session.execute(bs);\n} catch (com.datastax.oss.driver.api.core.servererrors.InvalidQueryException e) {\n    if (e.getMessage().contains(\"Invalid null value of timestamp\"))\n        log.error(\"Bind a real timestamp or unset the USING TIMESTAMP term\");\n    throw e;\n}","preventionTips":["Never bind null into USING TIMESTAMP markers","Use driver unset values for optional USING clauses","Add client-side null checks for write-metadata parameters","For JSON inserts, omit the timestamp field instead of sending null"],"tags":["cql","timestamp","invalid-request"],"backgroundTag":"null-argument","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}