{"record":{"id":"dcce5104fd568607","repo":"TheAlgorithms/Java","slug":"input-cannot-be-null-or-empty","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/OctalToDecimal.java","lineNumber":24,"sourceCode":" */\npublic final class OctalToDecimal {\n    private static final int OCTAL_BASE = 8;\n\n    private OctalToDecimal() {\n    }\n\n    /**\n     * Converts a given octal number (as a string) to its decimal representation.\n     * If the input is not a valid octal number (i.e., contains characters other than 0-7),\n     * the method throws an IllegalArgumentException.\n     *\n     * @param inputOctal The octal number as a string\n     * @return The decimal equivalent of the octal number\n     * @throws IllegalArgumentException if the input is not a valid octal number\n     */\n    public static int convertOctalToDecimal(String inputOctal) {\n        if (inputOctal == null || inputOctal.isEmpty()) {\n            throw new IllegalArgumentException(\"Input cannot be null or empty\");\n        }\n\n        int decimalValue = 0;\n\n        for (int i = 0; i < inputOctal.length(); i++) {\n            char currentChar = inputOctal.charAt(i);\n\n            if (currentChar < '0' || currentChar > '7') {\n                throw new IllegalArgumentException(\"Incorrect input: Expecting an octal number (digits 0-7)\");\n            }\n\n            int currentDigit = currentChar - '0';\n            decimalValue = decimalValue * OCTAL_BASE + currentDigit;\n        }\n\n        return decimalValue;\n    }\n}","sourceCodeStart":6,"sourceCodeEnd":42,"githubUrl":"https://github.com/TheAlgorithms/Java/blob/fdfb9a395b310167a66bd29e311e36e0e3e9b964/src/main/java/com/thealgorithms/conversions/OctalToDecimal.java#L6-L42","documentation":"Thrown by OctalToDecimal.convertOctalToDecimal when the inputOctal string is null or empty. This is the first guard before the character-by-character parsing loop begins. An empty string has no digits to process, and a null string would cause a NullPointerException in the loop.","triggerScenarios":"Calling convertOctalToDecimal(null) or convertOctalToDecimal(\"\"). Passing a variable that was not initialized or whose source returned an empty value. Providing an empty field from user input or a parsed data file.","commonSituations":"A form field for octal input is left blank. A file/CSV column is empty for some rows. A function parameter is conditionally set and the condition was not met, leaving the string null.","solutions":["Check for null or empty before calling convertOctalToDecimal and handle the case explicitly.","If empty input should map to zero, return 0 yourself instead of relying on the library.","Use a utility like StringUtils from Apache Commons to reject blank strings at the boundary."],"exampleFix":"// before\nint result = OctalToDecimal.convertOctalToDecimal(octalStr);\n\n// after\nif (octalStr == null || octalStr.isEmpty()) {\n    throw new IllegalArgumentException(\"Octal input must not be null or empty\");\n    // or: return 0; // if empty should mean zero\n}\nint result = OctalToDecimal.convertOctalToDecimal(octalStr);","handlingStrategy":"validation","validationCode":"if (inputOctal == null || inputOctal.isEmpty()) {\n    throw new IllegalArgumentException(\"Octal input must not be null or empty\");\n}\nint result = OctalToDecimal.convertOctalToDecimal(inputOctal);","typeGuard":"static boolean isValidOctalInput(String s) {\n    return s != null && !s.isEmpty() && s.matches(\"^[0-7]+$\");\n}","tryCatchPattern":"try {\n    int result = OctalToDecimal.convertOctalToDecimal(inputOctal);\n} catch (IllegalArgumentException e) {\n    // null, empty, or invalid octal input; handle gracefully\n    logger.warn(\"Invalid octal input: {}\", inputOctal);\n}","preventionTips":["Combine the null/empty check with a digit validation (^[0-7]+$) in a single guard.","If empty input should mean zero, handle it explicitly before calling the library.","Validate string inputs at the data boundary, not deep in the call chain."],"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"}