{"record":{"id":"dc9c806d0becd2fb","repo":"TheAlgorithms/Java","slug":"null-input","errorCode":"NULL_INPUT","errorMessage":"Invalid Input. 'null' or empty input provided","messagePattern":"Invalid Input\\. 'null' or empty input provided","errorType":"validation","errorClass":"WordsToNumberException","httpStatus":null,"severity":"error","filePath":"src/main/java/com/thealgorithms/conversions/WordsToNumber.java","lineNumber":98,"sourceCode":"\n        PowerOfTen(String word, BigDecimal value) {\n            this.word = word;\n            this.value = value;\n        }\n\n        public static BigDecimal getValue(String word) {\n            for (PowerOfTen power : values()) {\n                if (word.equals(power.word)) {\n                    return power.value;\n                }\n            }\n            return null;\n        }\n    }\n\n    public static String convert(String numberInWords) {\n        if (numberInWords == null) {\n            throw new WordsToNumberException(WordsToNumberException.ErrorType.NULL_INPUT, \"\");\n        }\n\n        ArrayDeque<String> wordDeque = preprocessWords(numberInWords);\n        BigDecimal completeNumber = convertWordQueueToBigDecimal(wordDeque);\n\n        return completeNumber.toString();\n    }\n\n    public static BigDecimal convertToBigDecimal(String numberInWords) {\n        String conversionResult = convert(numberInWords);\n        return new BigDecimal(conversionResult);\n    }\n\n    private static ArrayDeque<String> preprocessWords(String numberInWords) {\n        String[] wordSplitArray = numberInWords.trim().split(\"[ ,-]\");\n        ArrayDeque<String> wordDeque = new ArrayDeque<>();\n        for (String word : wordSplitArray) {\n            if (word.isEmpty()) {","sourceCodeStart":80,"sourceCodeEnd":116,"githubUrl":"https://github.com/TheAlgorithms/Java/blob/fdfb9a395b310167a66bd29e311e36e0e3e9b964/src/main/java/com/thealgorithms/conversions/WordsToNumber.java#L80-L116","documentation":"Thrown by WordsToNumber.convert when numberInWords is null (the very first guard). The message reads 'null or empty input' but this specific site only fires on a literal null reference. An empty/whitespace string is caught later in preprocessWords (error 104).","triggerScenarios":"Passing null explicitly: convert(null). Passing a variable that was never initialized or came from a map.get() that returned null.","commonSituations":"Unboxing results from optional/map lookups without null checks; deserialization producing null fields; optional user input fields that were left blank and defaulted to null.","solutions":["Null-check the input before calling convert.","Use Optional or a default value for the input string.","Validate at the boundary where the string enters your code."],"exampleFix":"// before\nString result = WordsToNumber.convert(maybeNullInput);\n// after\nString result = WordsToNumber.convert(\n    Objects.requireNonNullElseGet(input, () -> { throw new IllegalArgumentException(\"input required\"); }));","handlingStrategy":"validation","validationCode":"static String convertSafe(String input) {\n    if (input == null) throw new IllegalArgumentException(\"numberInWords must not be null\");\n    return WordsToNumber.convert(input);\n}","typeGuard":"static boolean isNonNullOrBlank(String s) {\n    return s != null;\n}","tryCatchPattern":"try {\n    return WordsToNumber.convert(input);\n} catch (WordsToNumberException e) {\n    if (e.errorType == ErrorType.NULL_INPUT) throw new ApiException(400, \"input is required\");\n    throw e;\n}","preventionTips":["Null-check at the boundary where input enters your code.","Use @NotNull annotations and static analysis to catch null propagation.","Prefer Optional for values that may be absent."],"tags":["java","words-to-number","null-input","input-validation"],"backgroundTag":null,"analyzedSha":"fdfb9a395b310167a66bd29e311e36e0e3e9b964","analyzedAt":"2026-08-13T23:36:13.315Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}