{"record":{"id":"5a2fe47589e102ba","repo":"TheAlgorithms/Java","slug":"input-parameter-must-not-be-negative","errorCode":null,"errorMessage":"Input parameter must not be negative!","messagePattern":"Input parameter must not be negative!","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/com/thealgorithms/maths/PalindromeNumber.java","lineNumber":26,"sourceCode":" * @see com.thealgorithms.stacks.PalindromeWithStack\n * @see com.thealgorithms.bitmanipulation.BinaryPalindromeCheck\n * @see com.thealgorithms.maths.LowestBasePalindrome\n * @see com.thealgorithms.datastructures.lists.PalindromeSinglyLinkedList\n * @see com.thealgorithms.maths.PalindromePrime\n */\npublic final class PalindromeNumber {\n    private PalindromeNumber() {\n    }\n    /**\n     * Check if {@code n} is palindrome number or not\n     *\n     * @param number the number\n     * @return {@code true} if {@code n} is palindrome number, otherwise\n     * {@code false}\n     */\n    public static boolean isPalindrome(int number) {\n        if (number < 0) {\n            throw new IllegalArgumentException(\"Input parameter must not be negative!\");\n        }\n        int numberCopy = number;\n        int reverseNumber = 0;\n        while (numberCopy != 0) {\n            int remainder = numberCopy % 10;\n            reverseNumber = reverseNumber * 10 + remainder;\n            numberCopy /= 10;\n        }\n        return number == reverseNumber;\n    }\n}\n","sourceCodeStart":8,"sourceCodeEnd":38,"githubUrl":"https://github.com/TheAlgorithms/Java/blob/fdfb9a395b310167a66bd29e311e36e0e3e9b964/src/main/java/com/thealgorithms/maths/PalindromeNumber.java#L8-L38","documentation":"Thrown by PalindromeNumber.isPalindrome(int number) when number is negative. Negative integers cannot be palindromes by this implementation's definition (the minus sign is not a digit), and the digit-reversal loop assumes a non-negative input. The guard rejects negatives before reversing.","triggerScenarios":"Calling isPalindrome(-121) or any isPalindrome(number) where number < 0.","commonSituations":"Parsed integer from user input or a payload without sign validation; result of a computation (e.g., difference) fed in directly; assumption that the method handles negatives when it does not.","solutions":["Decide on domain semantics: either reject negatives upstream as non-palindromes, or pass Math.abs(number) if magnitude-based checking is acceptable.","Validate at the input boundary that the value is non-negative.","Fix upstream logic so only non-negative values reach the call."],"exampleFix":"// before\nboolean p = PalindromeNumber.isPalindrome(value);\n\n// after\nboolean p = value < 0 ? false : PalindromeNumber.isPalindrome(value);","handlingStrategy":"validation","validationCode":"boolean p = number < 0 ? false : PalindromeNumber.isPalindrome(number);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Decide on domain semantics for negatives (typically not palindromes) and short-circuit.","Validate parsed integers for sign before the call.","Document whether abs()-based checking is acceptable for your use case."],"tags":["math","palindrome","invalid-argument","negative-value"],"backgroundTag":null,"analyzedSha":"fdfb9a395b310167a66bd29e311e36e0e3e9b964","analyzedAt":"2026-08-13T23:36:13.315Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}