{"record":{"id":"e314a1e9274387b7","repo":"TheAlgorithms/Java","slug":"base-must-be-greater-than-1","errorCode":null,"errorMessage":"Base must be greater than 1.","messagePattern":"Base must be greater than 1\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/com/thealgorithms/maths/LowestBasePalindrome.java","lineNumber":46,"sourceCode":" * @see com.thealgorithms.bitmanipulation.BinaryPalindromeCheck\n * @see com.thealgorithms.datastructures.lists.PalindromeSinglyLinkedList\n * @see com.thealgorithms.maths.PalindromePrime\n * @see com.thealgorithms.maths.PalindromeNumber\n * @author TheAlgorithms Contributors\n */\npublic final class LowestBasePalindrome {\n    private LowestBasePalindrome() {\n    }\n\n    /**\n     * Validates the base, ensuring it is greater than 1.\n     *\n     * @param base the base to be checked\n     * @throws IllegalArgumentException if the base is less than or equal to 1\n     */\n    private static void checkBase(int base) {\n        if (base <= 1) {\n            throw new IllegalArgumentException(\"Base must be greater than 1.\");\n        }\n    }\n\n    /**\n     * Validates the number, ensuring it is non-negative.\n     *\n     * @param number the number to be checked\n     * @throws IllegalArgumentException if the number is negative\n     */\n    private static void checkNumber(int number) {\n        if (number < 0) {\n            throw new IllegalArgumentException(\"Number must be non-negative.\");\n        }\n    }\n\n    /**\n     * Computes the digits of a given number in a specified base.\n     * <p>","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/TheAlgorithms/Java/blob/fdfb9a395b310167a66bd29e311e36e0e3e9b964/src/main/java/com/thealgorithms/maths/LowestBasePalindrome.java#L28-L64","documentation":"Thrown by the private checkBase(int base) method, invoked by computeDigitsInBase(number, base) and isPalindromicInBase(number, base). A numeric base must be >= 2 because base-1 and base-0 representations are mathematically undefined for the digit-extraction algorithm used (number % base and number / base).","triggerScenarios":"Calling LowestBasePalindrome.computeDigitsInBase(10, 1), computeDigitsInBase(10, 0), or isPalindromicInBase(15, 1). Any call with a base parameter <= 1.","commonSituations":"Passing a user-configured base value that defaults to 0 or 1. Off-by-one when iterating bases from 1 instead of 2. Confusing base-1 indexing with numeric radix.","solutions":["Ensure the base parameter is >= 2 before calling computeDigitsInBase or isPalindromicInBase","If accepting user input for base, validate and reject values below 2 at the input boundary","Start base-iteration loops at 2"],"exampleFix":"// before\nList<Integer> digits = LowestBasePalindrome.computeDigitsInBase(num, base);\n\n// after\nif (base < 2) throw new IllegalArgumentException(\"Base must be >= 2\");\nList<Integer> digits = LowestBasePalindrome.computeDigitsInBase(num, base);","handlingStrategy":"validation","validationCode":"if (base < 2) {\n    throw new IllegalArgumentException(\"Base must be >= 2: \" + base);\n}\nList<Integer> digits = LowestBasePalindrome.computeDigitsInBase(number, base);","typeGuard":"static boolean isValidBase(int base) {\n    return base >= 2;\n}","tryCatchPattern":null,"preventionTips":["Always start base-iteration loops at 2, never 0 or 1","Validate user-provided base values at the input boundary","Remember that base-1 (unary) is not supported by this library"],"tags":["math","validation","illegal-argument","number-theory"],"backgroundTag":null,"analyzedSha":"fdfb9a395b310167a66bd29e311e36e0e3e9b964","analyzedAt":"2026-08-13T23:36:13.315Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}