{"record":{"id":"89f67feaf5106bc4","repo":"apache/cassandra","slug":"invalid-timestamp","errorCode":null,"errorMessage":"Invalid Timestamp: ","messagePattern":"Invalid Timestamp: ","errorType":"validation","errorClass":"MarshalException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/db/marshal/TimestampUtf8Type.java","lineNumber":41,"sourceCode":"\nimport org.apache.cassandra.cql3.functions.ArgumentDeserializer;\nimport org.apache.cassandra.serializers.MarshalException;\nimport org.apache.cassandra.serializers.TypeSerializer;\nimport org.apache.cassandra.serializers.UTF8Serializer;\nimport org.apache.cassandra.utils.ByteBufferUtil;\n\npublic class TimestampUtf8Type extends PseudoUtf8Type\n{\n    public static final TimestampUtf8Type instance = new TimestampUtf8Type();\n    static final TypeSerializer<String> timestampSerializer = new UTF8Serializer()\n    {\n        @Override\n        public <V> void validate(V value, ValueAccessor<V> accessor) throws MarshalException\n        {\n            super.validate(value, accessor);\n            String str = deserialize(value, accessor);\n            if (!str.isEmpty() && null == Timestamp.tryParse(str))\n                throw new MarshalException(\"Invalid Timestamp: \" + str);\n        }\n    };\n\n    private static final ArgumentDeserializer ARGUMENT_DESERIALIZER = new DefaultArgumentDeserializer(instance);\n    private static final ByteBuffer MASKED_VALUE = ByteBufferUtil.EMPTY_BYTE_BUFFER;\n\n    TimestampUtf8Type() {} // singleton\n\n    String describe() { return \"TxnId\"; }\n\n    @Override\n    public TypeSerializer<String> getSerializer()\n    {\n        return timestampSerializer;\n    }\n\n    @Override\n    public <VL, VR> int compareCustom(VL left, ValueAccessor<VL> accessorL, VR right, ValueAccessor<VR> accessorR)","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/db/marshal/TimestampUtf8Type.java#L23-L59","documentation":"TimestampUtf8Type stores timestamps as UTF-8 strings and its validator re-checks every value: the string must be non-empty and parseable by Timestamp.tryParse. Values that parse as UTF-8 but not as a timestamp fail with this MarshalException, so it is stricter than plain utf8 validation.","triggerScenarios":"Inserting/updating a column (e.g. a SASI/indexable timestamp-as-string column) with text like 'not-a-date', '2026-13-45', or an empty check that fails Timestamp.tryParse; UDF/secondary-index validation paths invoking validate().","commonSituations":"Free-text input bound to a timestamp-as-string column; locale-specific date formats that Cassandra's parser does not accept; truncated date strings from string-slicing code.","solutions":["Pre-validate on the client with Timestamp.tryParse (or java.time parsing) before binding.","Send dates in Cassandra's expected format (yyyy-MM-dd HH:mm:ss[.SSS] or ISO variants).","Use TimestampType (binary) instead of TimestampUtf8Type if you don't need string storage."],"exampleFix":"// before\nString val = userSuppliedDate; // \"09/09/2026\"\n// after\nif (com.datastax.driver.core.LocalDate.class != null && !isParseableTimestamp(userSuppliedDate))\n    throw new IllegalArgumentException(\"invalid timestamp: \" + userSuppliedDate);","handlingStrategy":"validation","validationCode":"if (str != null && !str.isEmpty() && com.datastax... ) boolean valid = Timestamp.tryParse(str) != null; // or try java.time parse with expected formats","typeGuard":null,"tryCatchPattern":"try { type.validate(bb, ByteBufferAccessor.instance); } catch (MarshalException e) { /* reject input: e.getMessage() */ }","preventionTips":["Pre-parse timestamps with java.time using the exact formats Cassandra accepts","Use TimestampType instead of the UTF8 variant when string storage is not required","Reject free-text input for timestamp columns at the UI layer"],"tags":["cassandra","validation","timestamp","marshal"],"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"}