{"record":{"id":"6a49584dff3c695d","repo":"TheAlgorithms/Java","slug":"unknown-roman-symbol","errorCode":null,"errorMessage":"Unknown Roman symbol: {}","messagePattern":"Unknown Roman symbol: (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/com/thealgorithms/conversions/RomanToInteger.java","lineNumber":51,"sourceCode":"            put('L', 50);\n            put('C', 100);\n            put('D', 500);\n            put('M', 1000);\n        }\n    };\n\n    private RomanToInteger() {\n    }\n\n    /**\n     * Converts a single Roman numeral character to its integer value.\n     *\n     * @param symbol the Roman numeral character\n     * @return the corresponding integer value\n     * @throws IllegalArgumentException if the symbol is not a valid Roman numeral\n     */\n    private static int romanSymbolToInt(final char symbol) {\n        return ROMAN_TO_INT.computeIfAbsent(symbol, c -> { throw new IllegalArgumentException(\"Unknown Roman symbol: \" + c); });\n    }\n\n    /**\n     * Converts a Roman numeral string to its integer equivalent.\n     * Steps:\n     * <ol>\n     *     <li>Iterate over the string from right to left.</li>\n     *     <li>For each character, convert it to an integer value.</li>\n     *     <li>If the current value is greater than or equal to the max previous value, add it.</li>\n     *     <li>Otherwise, subtract it from the sum.</li>\n     *     <li>Update the max previous value.</li>\n     *     <li>Return the sum.</li>\n     * </ol>\n     *\n     * @param roman the Roman numeral string\n     * @return the integer value of the Roman numeral\n     * @throws IllegalArgumentException if the input contains invalid Roman characters\n     * @throws NullPointerException if the input is {@code null}","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/TheAlgorithms/Java/blob/fdfb9a395b310167a66bd29e311e36e0e3e9b964/src/main/java/com/thealgorithms/conversions/RomanToInteger.java#L33-L69","documentation":"Thrown by RomanToInteger.romanSymbolToInt (called internally by romanToInt) when a character in the input string is not one of the seven valid Roman numeral symbols: I, V, X, L, C, D, M. The method uppercases the input first, so lowercase variants are accepted, but any other character triggers this error. The offending character is included in the error message.","triggerScenarios":"Passing strings containing spaces, digits, punctuation, or letters outside the Roman set (e.g., 'XII A', '1V', 'MCM@XC'). Providing Arabic numerals instead of Roman. Including leading/trailing whitespace that is not trimmed.","commonSituations":"User input that was not validated before conversion. Data from a source that mixes Roman numerals with other text. Whitespace or formatting characters embedded in the string from a file or database.","solutions":["Trim whitespace and validate the input with a regex like ^[IVXLCDMivxlcdm]+$ before calling romanToInt.","If the input may contain prefixes or suffixes, strip them before conversion.","Provide a clear input format specification at the UI or API boundary."],"exampleFix":"// before\nint result = RomanToInteger.romanToInt(romanStr);\n\n// after\nromanStr = romanStr.trim();\nif (!romanStr.matches(\"^[IVXLCDMivxlcdm]+$\")) {\n    throw new IllegalArgumentException(\"Input must contain only Roman numeral characters I, V, X, L, C, D, M: \" + romanStr);\n}\nint result = RomanToInteger.romanToInt(romanStr);","handlingStrategy":"validation","validationCode":"roman = roman.trim();\nif (!roman.matches(\"^[IVXLCDMivxlcdm]+$\")) {\n    throw new IllegalArgumentException(\"Input must contain only Roman numeral characters: \" + roman);\n}\nint result = RomanToInteger.romanToInt(roman);","typeGuard":"static boolean isValidRoman(String s) {\n    return s != null && !s.isEmpty() && s.trim().matches(\"^[IVXLCDMivxlcdm]+$\");\n}","tryCatchPattern":"try {\n    int result = RomanToInteger.romanToInt(roman);\n} catch (IllegalArgumentException e) {\n    // invalid character present; log and skip or sanitize\n    logger.warn(\"Invalid Roman numeral: {}\", roman);\n}","preventionTips":["Trim whitespace and validate with ^[IVXLCDMivxlcdm]+$ before conversion.","Provide an explicit format specification for Roman numeral inputs at the UI or API boundary.","If the input may contain formatting characters, strip them before validation."],"tags":["roman-numerals","input-validation"],"backgroundTag":null,"analyzedSha":"fdfb9a395b310167a66bd29e311e36e0e3e9b964","analyzedAt":"2026-08-13T23:36:13.315Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}