{"record":{"id":"f8847eabace6e45e","repo":"TheAlgorithms/Java","slug":"invalid-numeric-part-part","errorCode":null,"errorMessage":"Invalid numeric part: {part}","messagePattern":"Invalid numeric part: (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/com/thealgorithms/maths/ZellersCongruence.java","lineNumber":92,"sourceCode":"    /**\n     * Parses a part of the date string and validates its range.\n     *\n     * @param part  the substring to parse\n     * @param min   the minimum valid value\n     * @param max   the maximum valid value\n     * @param error the error message to throw if validation fails\n     * @return the parsed integer value\n     * @throws IllegalArgumentException if the part is not a valid number or is out of range\n     */\n    private static int parsePart(String part, int min, int max, String error) {\n        try {\n            int value = Integer.parseInt(part);\n            if (value < min || value > max) {\n                throw new IllegalArgumentException(error);\n            }\n            return value;\n        } catch (NumberFormatException e) {\n            throw new IllegalArgumentException(\"Invalid numeric part: \" + part, e);\n        }\n    }\n\n    /**\n     * Validates the separator character in the date string.\n     *\n     * @param sep the separator character\n     * @throws IllegalArgumentException if the separator is not '-' or '/'\n     */\n    private static void validateSeparator(char sep) {\n        if (sep != '-' && sep != '/') {\n            throw new IllegalArgumentException(\"Date separator must be '-' or '/'.\");\n        }\n    }\n}\n","sourceCodeStart":74,"sourceCodeEnd":108,"githubUrl":"https://github.com/TheAlgorithms/Java/blob/fdfb9a395b310167a66bd29e311e36e0e3e9b964/src/main/java/com/thealgorithms/maths/ZellersCongruence.java#L74-L108","documentation":"Thrown by ZellersCongruence.parsePart when Integer.parseInt(part) raises NumberFormatException, i.e., one of the fixed substrings (month/day/year) contains non-digit characters. The original NumberFormatException is chained as the cause, and the offending substring is echoed in the message.","triggerScenarios":"Call calculateDay(\"0a-01-2020\"), calculateDay(\"01- 1-2020\") (space), calculateDay(\"AB-CD-EFGH\"), or any input where a numeric field contains a letter/space/symbol.","commonSituations":"Mixed locale separators leaking into the digit fields, OCR/copy-paste artifacts (e.g., non-breaking space), user-typed alphabetic month abbreviations ('Jan'), or a field that was never sanitized.","solutions":["Sanitize each field to digits-only before formatting, or construct the input only from validated ints.","Use a regex like ^\\d{2}[-/]\\d{2}[-/]\\d{4}$ to pre-validate the whole string.","Parse with DateTimeFormatter which yields clearer date-parse errors."],"exampleFix":"// before\nString day = ZellersCongruence.calculateDay(raw);\n\n// after\nif (!raw.matches(\"\\\\d{2}[-/]\\\\d{2}[-/]\\\\d{4}\")) {\n    throw new IllegalArgumentException(\"Bad date format: \" + raw);\n}\nString day = ZellersCongruence.calculateDay(raw);","handlingStrategy":"validation","validationCode":"if (!input.matches(\"\\\\d{2}[-/]\\\\d{2}[-/]\\\\d{4}\")) {\n    throw new IllegalArgumentException(\"Date fields must be numeric with '-' or '/' separators\");\n}\nString d = ZellersCongruence.calculateDay(input);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use a single regex to validate the whole date shape before handing off to the util.","Construct input strings from validated ints rather than concatenating raw user text."],"tags":["date","zellers-congruence","parse-error","format-validation"],"backgroundTag":null,"analyzedSha":"fdfb9a395b310167a66bd29e311e36e0e3e9b964","analyzedAt":"2026-08-13T23:36:13.315Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}