apache/cassandra · error · MarshalException

Unable to make unsigned int (for date) from: '%s'

Error message

Unable to make unsigned int (for date) from: '%s'

What it means

When the input string is not an ISO date, SimpleDateSerializer.parseRaw attempts to interpret it as the raw unsigned-int day encoding (a plain decimal string). This error means the string could not be parsed as a number (or as a date) to produce that unsigned int for the date type.

Source

Thrown at src/java/org/apache/cassandra/serializers/SimpleDateSerializer.java:104

    }

    private static int parseRaw(String source) {
        try
        {
            long result = Long.parseLong(source);

            if (result < 0 || result > maxSupportedDays)
                throw new NumberFormatException("Input out of bounds: " + source);

            // Shift > epoch days into negative portion of Integer result for byte order comparability
            if (result >= Integer.MAX_VALUE)
                result -= byteOrderShift;

            return (int) result;
        }
        catch (NumberFormatException | DateTimeParseException e)
        {
            throw new MarshalException(String.format("Unable to make unsigned int (for date) from: '%s'", source), e);
        }
    }

    public static int timeInMillisToDay(long millis)
    {
        return (int) (Duration.ofMillis(millis).toDays() - Integer.MIN_VALUE);
    }

    public static long dayToTimeInMillis(int days)
    {
        return Duration.ofDays(days + Integer.MIN_VALUE).toMillis();
    }

    public <V> void validate(V value, ValueAccessor<V> accessor) throws MarshalException
    {
        if (accessor.size(value) != 4)
            throw new MarshalException(String.format("Expected 4 byte long for date (%d)", accessor.size(value)));
    }

View on GitHub (pinned to 88fd0f6a0e)

Solutions

  1. Pass either an ISO date string ('2011-02-03') or the exact unsigned-int decimal encoding as a string
  2. Trim whitespace and remove any time-of-day portion from the input
  3. If you have epoch millis, convert with the serializer: days encoding = Duration.ofMillis(millis).toDays() - Integer.MIN_VALUE, then pass String.valueOf that int
  4. Pre-validate: the string must match ^-?\d+$ or ISO_LOCAL_DATE

Example fix

// before
session.execute("INSERT INTO t (d) VALUES (?)", "2011-02-03 04:05:06");
// after
session.execute("INSERT INTO t (d) VALUES (?)", "2011-02-03");
Defensive patterns

Strategy: validation

Validate before calling

if (!input.matches("^[+-]?\\d{4,}-\\d{2}-\\d{2}$") && !input.matches("^-?\\d+$")) throw new IllegalArgumentException("not a date string or raw day encoding: " + input);

Type guard

null

Try / catch

try {
  int days = SimpleDateSerializer.dateStringToDays(input);
} catch (MarshalException e) {
  throw new BadRequestException("value must be ISO yyyy-MM-dd or an unsigned-int day encoding");
}

Prevention

When it happens

Trigger: dateStringToDays falls through to parseRaw with a non-numeric, non-ISO string (e.g. 'abc', '1.5', '2020-01-01T10:00:00', negative encodings outside int range); NumberFormatException or DateTimeParseException is then wrapped in this MarshalException.

Common situations: Passing a full timestamp string to a date column; passing a date string with time component; garbage/untrimmed input from CSV imports; sending a negative number that overflows the unsigned encoding math.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


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