{"record":{"id":"168471457a86c10e","repo":"apache/cassandra","slug":"unable-to-make-unsigned-int-for-date-from-s","errorCode":null,"errorMessage":"Unable to make unsigned int (for date) from: '%s'","messagePattern":"Unable to make unsigned int \\(for date\\) from: '(.+?)'","errorType":"validation","errorClass":"MarshalException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/serializers/SimpleDateSerializer.java","lineNumber":104,"sourceCode":"    }\n\n    private static int parseRaw(String source) {\n        try\n        {\n            long result = Long.parseLong(source);\n\n            if (result < 0 || result > maxSupportedDays)\n                throw new NumberFormatException(\"Input out of bounds: \" + source);\n\n            // Shift > epoch days into negative portion of Integer result for byte order comparability\n            if (result >= Integer.MAX_VALUE)\n                result -= byteOrderShift;\n\n            return (int) result;\n        }\n        catch (NumberFormatException | DateTimeParseException e)\n        {\n            throw new MarshalException(String.format(\"Unable to make unsigned int (for date) from: '%s'\", source), e);\n        }\n    }\n\n    public static int timeInMillisToDay(long millis)\n    {\n        return (int) (Duration.ofMillis(millis).toDays() - Integer.MIN_VALUE);\n    }\n\n    public static long dayToTimeInMillis(int days)\n    {\n        return Duration.ofDays(days + Integer.MIN_VALUE).toMillis();\n    }\n\n    public <V> void validate(V value, ValueAccessor<V> accessor) throws MarshalException\n    {\n        if (accessor.size(value) != 4)\n            throw new MarshalException(String.format(\"Expected 4 byte long for date (%d)\", accessor.size(value)));\n    }","sourceCodeStart":86,"sourceCodeEnd":122,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/serializers/SimpleDateSerializer.java#L86-L122","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Pass either an ISO date string ('2011-02-03') or the exact unsigned-int decimal encoding as a string","Trim whitespace and remove any time-of-day portion from the input","If you have epoch millis, convert with the serializer: days encoding = Duration.ofMillis(millis).toDays() - Integer.MIN_VALUE, then pass String.valueOf that int","Pre-validate: the string must match ^-?\\d+$ or ISO_LOCAL_DATE"],"exampleFix":"// before\nsession.execute(\"INSERT INTO t (d) VALUES (?)\", \"2011-02-03 04:05:06\");\n// after\nsession.execute(\"INSERT INTO t (d) VALUES (?)\", \"2011-02-03\");","handlingStrategy":"validation","validationCode":"if (!input.matches(\"^[+-]?\\\\d{4,}-\\\\d{2}-\\\\d{2}$\") && !input.matches(\"^-?\\\\d+$\")) throw new IllegalArgumentException(\"not a date string or raw day encoding: \" + input);","typeGuard":"null","tryCatchPattern":"try {\n  int days = SimpleDateSerializer.dateStringToDays(input);\n} catch (MarshalException e) {\n  throw new BadRequestException(\"value must be ISO yyyy-MM-dd or an unsigned-int day encoding\");\n}","preventionTips":["Trim and normalize all date inputs before insert","Keep date and timestamp columns distinct; never route datetime strings into date columns","For CSV imports, map the column to ISO format during ETL","Add unit tests covering both accepted input forms (ISO string, raw int string)"],"tags":["cassandra","serialization","date","number-format"],"backgroundTag":"invalid-argument-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"}