{"record":{"id":"45bce4099476840c","repo":"TheAlgorithms/Java","slug":"the-number-must-be-in-the-range-d-d","errorCode":null,"errorMessage":"The number must be in the range [%d, %d]","messagePattern":"The number must be in the range \\[(.+?), (.+?)\\]","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/com/thealgorithms/maths/RomanNumeralUtil.java","lineNumber":68,"sourceCode":"        \"XC\",\n    };\n    // 1-9\n    private static final String[] RN_I = {\n        \"\",\n        \"I\",\n        \"II\",\n        \"III\",\n        \"IV\",\n        \"V\",\n        \"VI\",\n        \"VII\",\n        \"VIII\",\n        \"IX\",\n    };\n\n    public static String generate(int number) {\n        if (number < MIN_VALUE || number > MAX_VALUE) {\n            throw new IllegalArgumentException(String.format(\"The number must be in the range [%d, %d]\", MIN_VALUE, MAX_VALUE));\n        }\n\n        return (RN_M[number / 1000] + RN_C[number % 1000 / 100] + RN_X[number % 100 / 10] + RN_I[number % 10]);\n    }\n}\n","sourceCodeStart":50,"sourceCodeEnd":74,"githubUrl":"https://github.com/TheAlgorithms/Java/blob/fdfb9a395b310167a66bd29e311e36e0e3e9b964/src/main/java/com/thealgorithms/maths/RomanNumeralUtil.java#L50-L74","documentation":"Thrown by RomanNumeralUtil.generate(int) when the input falls outside the supported additive Roman numeral range [1, 5999]. The lookup tables RN_M/RN_C/RN_X/RN_I only cover up to 5999 (MMMMM...), and zero/negative values have no Roman numeral representation, so the guard rejects them before an ArrayIndexOutOfBoundsException or garbage output could occur.","triggerScenarios":"Call RomanNumeralUtil.generate(0), generate(-1), generate(6000), or generate with any int < 1 or > 5999. Also hit by passing Integer.MAX_VALUE or a parsed user value that overflowed a bound check upstream.","commonSituations":"Off-by-one loop counters starting at 0, unchecked external input parsed into an int, code that assumed Roman numerals are unbounded, or a refactor that changed the expected domain without updating callers.","solutions":["Clamp or reject the input before calling generate(), ensuring 1 <= number <= 5999.","If you need values >= 6000, switch to a library that supports vinculum (overbar) notation instead of this util.","Add a unit test asserting generate(1) and generate(5999) succeed while generate(0) and generate(6000) throw."],"exampleFix":"// before\nString r = RomanNumeralUtil.generate(userValue);\n\n// after\nif (userValue < 1 || userValue > 5999) {\n    throw new IllegalArgumentException(\"Value out of Roman range: \" + userValue);\n}\nString r = RomanNumeralUtil.generate(userValue);","handlingStrategy":"validation","validationCode":"if (number < 1 || number > 5999) {\n    throw new IllegalArgumentException(\"Value out of Roman range [1,5999]: \" + number);\n}\nString r = RomanNumeralUtil.generate(number);","typeGuard":null,"tryCatchPattern":"try {\n    String r = RomanNumeralUtil.generate(number);\n} catch (IllegalArgumentException e) {\n    // surface a user-facing error; do not silently default\n    throw new DomainException(\"Unsupported value for Roman conversion\", e);\n}","preventionTips":["Treat the [1,5999] bound as part of the method's type contract and document it at every call site.","For values >= 6000, select a different library supporting vinculum notation."],"tags":["math","roman-numerals","input-validation","argument-validation"],"backgroundTag":null,"analyzedSha":"fdfb9a395b310167a66bd29e311e36e0e3e9b964","analyzedAt":"2026-08-13T23:36:13.315Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}