{"record":{"id":"d730a9ab19c4979b","repo":"TheAlgorithms/Java","slug":"input-value-must-be-a-positive-integer-input-valu","errorCode":null,"errorMessage":"Input value must be a positive integer. Input value: {number}","messagePattern":"Input value must be a positive integer\\. Input value: (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/com/thealgorithms/maths/GermainPrimeAndSafePrime.java","lineNumber":41,"sourceCode":" */\npublic final class GermainPrimeAndSafePrime {\n\n    // Private constructor to prevent instantiation\n    private GermainPrimeAndSafePrime() {\n    }\n\n    /**\n     * Checks if a number is a Germain prime.\n     *\n     * <p>A Germain prime is a prime number p such that 2p + 1 is also prime.\n     *\n     * @param number the number to check; must be a positive integer\n     * @return {@code true} if the number is a Germain prime, {@code false} otherwise\n     * @throws IllegalArgumentException if the input number is less than 1\n     */\n    public static boolean isGermainPrime(int number) {\n        if (number < 1) {\n            throw new IllegalArgumentException(\"Input value must be a positive integer. Input value: \" + number);\n        }\n        // A number is a Germain prime if it is prime and 2 * number + 1 is also prime\n        return PrimeCheck.isPrime(number) && PrimeCheck.isPrime(2 * number + 1);\n    }\n\n    /**\n     * Checks if a number is a Safe prime.\n     *\n     * <p>A Safe prime is a prime number p such that (p - 1) / 2 is also prime.\n     *\n     * @param number the number to check; must be a positive integer\n     * @return {@code true} if the number is a Safe prime, {@code false} otherwise\n     * @throws IllegalArgumentException if the input number is less than 1\n     */\n    public static boolean isSafePrime(int number) {\n        if (number < 1) {\n            throw new IllegalArgumentException(\"Input value must be a positive integer. Input value: \" + number);\n        }","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/TheAlgorithms/Java/blob/fdfb9a395b310167a66bd29e311e36e0e3e9b964/src/main/java/com/thealgorithms/maths/GermainPrimeAndSafePrime.java#L23-L59","documentation":"Thrown by GermainPrimeAndSafePrime.isGermainPrime(int number) when number is less than 1. A Germain prime is a prime p where 2p+1 is also prime, which requires p >= 2 (the smallest prime). The method rejects all non-positive inputs before delegating to PrimeCheck.isPrime. The exception message includes the offending value for diagnostics.","triggerScenarios":"Calling isGermainPrime(0), isGermainPrime(-1), or any negative integer. The method is a pure validation gate — any number >= 1 proceeds to the prime check, but mathematically only p >= 2 can be a Germain prime.","commonSituations":"Processing user-supplied integers without sanitization. Looping over ranges that start at or below zero. Receiving unvalidated input from external sources, configuration files, or parsed strings.","solutions":["Ensure number >= 1 before calling isGermainPrime (practically >= 2 since 1 is not prime).","Sanitize or clamp user input to positive integers at the entry point.","Wrap calls in try-catch(IllegalArgumentException) if input cannot be guaranteed."],"exampleFix":"// before\nboolean result = GermainPrimeAndSafePrime.isGermainPrime(userInput);\n\n// after\nif (userInput < 2) {\n    return false; // or throw a domain-specific exception\n}\nboolean result = GermainPrimeAndSafePrime.isGermainPrime(userInput);","handlingStrategy":"validation","validationCode":"if (number < 1) {\n    return false; // or throw a domain-specific exception\n}\nboolean result = GermainPrimeAndSafePrime.isGermainPrime(number);","typeGuard":"static boolean isPositive(int n) {\n    return n >= 1;\n}","tryCatchPattern":"try {\n    boolean result = GermainPrimeAndSafePrime.isGermainPrime(number);\n} catch (IllegalArgumentException e) {\n    // number < 1; not a valid candidate\n    result = false;\n}","preventionTips":["Ensure number >= 1 (practically >= 2 for primes) before calling.","Sanitize user input for positivity at the ingestion boundary.","Handle non-positive inputs with domain logic rather than relying on the exception."],"tags":["math","prime","argument-validation","positive-integer"],"backgroundTag":null,"analyzedSha":"fdfb9a395b310167a66bd29e311e36e0e3e9b964","analyzedAt":"2026-08-13T23:36:13.315Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}