{"record":{"id":"a758d937129fb259","repo":"TheAlgorithms/Java","slug":"input-cannot-be-null-or-empty-a758d9","errorCode":null,"errorMessage":"Input cannot be null or empty","messagePattern":"Input cannot be null or empty","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/com/thealgorithms/conversions/OctalToHexadecimal.java","lineNumber":25,"sourceCode":" */\npublic final class OctalToHexadecimal {\n    private static final int OCTAL_BASE = 8;\n    private static final int HEX_BASE = 16;\n    private static final String HEX_DIGITS = \"0123456789ABCDEF\";\n\n    private OctalToHexadecimal() {\n    }\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     *","sourceCodeStart":7,"sourceCodeEnd":43,"githubUrl":"https://github.com/TheAlgorithms/Java/blob/fdfb9a395b310167a66bd29e311e36e0e3e9b964/src/main/java/com/thealgorithms/conversions/OctalToHexadecimal.java#L7-L43","documentation":"Thrown by OctalToHexadecimal.octalToDecimal when the octalNumber string is null or empty. This guard precedes the digit-by-digit parsing loop; a null input would otherwise cause a NullPointerException and an empty input would silently return 0 without meaningful conversion.","triggerScenarios":"Calling octalToDecimal(null) or octalToDecimal(\"\"). Passing a variable populated from a config key that is missing. Supplying an empty string from a form field or parsed data source.","commonSituations":"A configuration property for an octal value is absent. A database column is null for some records. A user submits a form without filling in the octal field.","solutions":["Check for null or empty before calling octalToDecimal and handle the missing-value case.","If null/empty should default to zero, handle that explicitly in the caller.","Validate input at the data boundary — reject or normalize empty strings early."],"exampleFix":"// before\nint decimal = OctalToHexadecimal.octalToDecimal(octalStr);\n\n// after\nif (octalStr == null || octalStr.isEmpty()) {\n    throw new IllegalArgumentException(\"Octal input must not be null or empty\");\n}\nint decimal = OctalToHexadecimal.octalToDecimal(octalStr);","handlingStrategy":"validation","validationCode":"if (octalNumber == null || octalNumber.isEmpty()) {\n    throw new IllegalArgumentException(\"Octal input must not be null or empty\");\n}\nint result = OctalToHexadecimal.octalToDecimal(octalNumber);","typeGuard":"static boolean isValidOctalString(String s) {\n    return s != null && !s.isEmpty() && s.matches(\"^[0-7]+$\");\n}","tryCatchPattern":"try {\n    int result = OctalToHexadecimal.octalToDecimal(octalNumber);\n} catch (IllegalArgumentException e) {\n    // null, empty, or invalid input; handle gracefully\n    logger.warn(\"Invalid octal input: {}\", octalNumber);\n}","preventionTips":["Check for null and empty in the same guard that validates digits.","If null/empty should default to zero, handle it before calling the library.","Validate at the data entry point to prevent propagation."],"tags":["number-conversion","input-validation","octal","null-check"],"backgroundTag":null,"analyzedSha":"fdfb9a395b310167a66bd29e311e36e0e3e9b964","analyzedAt":"2026-08-13T23:36:13.315Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}