apache/cassandra · error · MarshalException

Invalid Timestamp:

Error message

Invalid Timestamp: 

What it means

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.

Source

Thrown at src/java/org/apache/cassandra/db/marshal/TimestampUtf8Type.java:41

import org.apache.cassandra.cql3.functions.ArgumentDeserializer;
import org.apache.cassandra.serializers.MarshalException;
import org.apache.cassandra.serializers.TypeSerializer;
import org.apache.cassandra.serializers.UTF8Serializer;
import org.apache.cassandra.utils.ByteBufferUtil;

public class TimestampUtf8Type extends PseudoUtf8Type
{
    public static final TimestampUtf8Type instance = new TimestampUtf8Type();
    static final TypeSerializer<String> timestampSerializer = new UTF8Serializer()
    {
        @Override
        public <V> void validate(V value, ValueAccessor<V> accessor) throws MarshalException
        {
            super.validate(value, accessor);
            String str = deserialize(value, accessor);
            if (!str.isEmpty() && null == Timestamp.tryParse(str))
                throw new MarshalException("Invalid Timestamp: " + str);
        }
    };

    private static final ArgumentDeserializer ARGUMENT_DESERIALIZER = new DefaultArgumentDeserializer(instance);
    private static final ByteBuffer MASKED_VALUE = ByteBufferUtil.EMPTY_BYTE_BUFFER;

    TimestampUtf8Type() {} // singleton

    String describe() { return "TxnId"; }

    @Override
    public TypeSerializer<String> getSerializer()
    {
        return timestampSerializer;
    }

    @Override
    public <VL, VR> int compareCustom(VL left, ValueAccessor<VL> accessorL, VR right, ValueAccessor<VR> accessorR)

View on GitHub (pinned to 88fd0f6a0e)

Solutions

  1. Pre-validate on the client with Timestamp.tryParse (or java.time parsing) before binding.
  2. Send dates in Cassandra's expected format (yyyy-MM-dd HH:mm:ss[.SSS] or ISO variants).
  3. Use TimestampType (binary) instead of TimestampUtf8Type if you don't need string storage.

Example fix

// before
String val = userSuppliedDate; // "09/09/2026"
// after
if (com.datastax.driver.core.LocalDate.class != null && !isParseableTimestamp(userSuppliedDate))
    throw new IllegalArgumentException("invalid timestamp: " + userSuppliedDate);
Defensive patterns

Strategy: validation

Validate before calling

if (str != null && !str.isEmpty() && com.datastax... ) boolean valid = Timestamp.tryParse(str) != null; // or try java.time parse with expected formats

Try / catch

try { type.validate(bb, ByteBufferAccessor.instance); } catch (MarshalException e) { /* reject input: e.getMessage() */ }

Prevention

When it happens

Trigger: 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().

Common situations: 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.

Related errors


AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10). Data as JSON: /api/errors/89f67feaf5106bc4. Report an issue: GitHub.