{"record":{"id":"cb4951d6d99bfe89","repo":"TheAlgorithms/Java","slug":"incorrect-octal-digit","errorCode":null,"errorMessage":"Incorrect octal digit: {}","messagePattern":"Incorrect octal digit: (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/com/thealgorithms/conversions/OctalToHexadecimal.java","lineNumber":32,"sourceCode":"    }\n\n    /**\n     * Converts an Octal number (as a string) to its Decimal equivalent.\n     *\n     * @param octalNumber The Octal number as a string\n     * @return The Decimal equivalent of the Octal number\n     * @throws IllegalArgumentException if the input contains invalid octal digits\n     */\n    public static int octalToDecimal(String octalNumber) {\n        if (octalNumber == null || octalNumber.isEmpty()) {\n            throw new IllegalArgumentException(\"Input cannot be null or empty\");\n        }\n\n        int decimalValue = 0;\n        for (int i = 0; i < octalNumber.length(); i++) {\n            char currentChar = octalNumber.charAt(i);\n            if (currentChar < '0' || currentChar > '7') {\n                throw new IllegalArgumentException(\"Incorrect octal digit: \" + currentChar);\n            }\n            int currentDigit = currentChar - '0';\n            decimalValue = decimalValue * OCTAL_BASE + currentDigit;\n        }\n\n        return decimalValue;\n    }\n\n    /**\n     * Converts a Decimal number to its Hexadecimal equivalent.\n     *\n     * @param decimalNumber The Decimal number\n     * @return The Hexadecimal equivalent of the Decimal number\n     */\n    public static String decimalToHexadecimal(int decimalNumber) {\n        if (decimalNumber == 0) {\n            return \"0\";\n        }","sourceCodeStart":14,"sourceCodeEnd":50,"githubUrl":"https://github.com/TheAlgorithms/Java/blob/fdfb9a395b310167a66bd29e311e36e0e3e9b964/src/main/java/com/thealgorithms/conversions/OctalToHexadecimal.java#L14-L50","documentation":"Thrown by OctalToHexadecimal.octalToDecimal when any character in the input string is outside the octal digit range '0'–'7'. The check uses char comparison (currentChar < '0' || currentChar > '7'), so characters '8', '9', letters, whitespace, signs, or special characters all trigger it. The offending character is included in the error message.","triggerScenarios":"Passing a string containing '8', '9', letters, whitespace, or any non-octal character. Providing input formatted with a prefix like '0o17'. Supplying a decimal or hex string to the octal converter by mistake.","commonSituations":"A data pipeline routes mixed-format numeric strings to the octal converter. User input is not validated before conversion. File permission representations contain unexpected characters.","solutions":["Validate the input with a regex like ^[0-7]+$ before calling octalToDecimal.","Strip any prefixes or whitespace, then re-validate.","If the input format is ambiguous, detect it first and route to the correct converter."],"exampleFix":"// before\nint decimal = OctalToHexadecimal.octalToDecimal(octalStr);\n\n// after\nif (!octalStr.matches(\"^[0-7]+$\")) {\n    throw new IllegalArgumentException(\"Input must contain only octal digits 0-7: \" + octalStr);\n}\nint decimal = OctalToHexadecimal.octalToDecimal(octalStr);","handlingStrategy":"validation","validationCode":"if (!octalNumber.matches(\"^[0-7]+$\")) {\n    throw new IllegalArgumentException(\"Input must contain only octal digits 0-7: \" + octalNumber);\n}\nint result = OctalToHexadecimal.octalToDecimal(octalNumber);","typeGuard":"static boolean isValidOctalDigits(String s) {\n    return s != null && s.matches(\"^[0-7]+$\");\n}","tryCatchPattern":"try {\n    int result = OctalToHexadecimal.octalToDecimal(octalNumber);\n} catch (IllegalArgumentException e) {\n    // non-octal character present; route to correct parser or reject\n    logger.warn(\"Invalid octal digit in: {}\", octalNumber);\n}","preventionTips":["Validate the full string with ^[0-7]+$ before conversion.","Strip prefixes and whitespace before validation.","Differentiate between octal, decimal, and hex inputs at the data routing stage."],"tags":["number-conversion","input-validation","octal"],"backgroundTag":null,"analyzedSha":"fdfb9a395b310167a66bd29e311e36e0e3e9b964","analyzedAt":"2026-08-13T23:36:13.315Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}