{"record":{"id":"2b80aea5c56cd4db","repo":"TheAlgorithms/Java","slug":"input-parameter-must-not-be-empty","errorCode":null,"errorMessage":"Input parameter must not be empty!","messagePattern":"Input parameter must not be empty!","errorType":"exception","errorClass":"NumberFormatException","httpStatus":null,"severity":"error","filePath":"src/main/java/com/thealgorithms/maths/ParseInteger.java","lineNumber":12,"sourceCode":"package com.thealgorithms.maths;\n\npublic final class ParseInteger {\n    private ParseInteger() {\n    }\n\n    private static void checkInput(final String s) {\n        if (s == null) {\n            throw new NumberFormatException(\"Input parameter must not be null!\");\n        }\n        if (s.isEmpty()) {\n            throw new NumberFormatException(\"Input parameter must not be empty!\");\n        }\n    }\n\n    private static void checkDigitAt(final String s, final int pos) {\n        if (!Character.isDigit(s.charAt(pos))) {\n            throw new NumberFormatException(\"Input parameter of incorrect format: \" + s);\n        }\n    }\n\n    private static int digitToInt(final char digit) {\n        return digit - '0';\n    }\n\n    /**\n     * Parse a string to integer\n     *\n     * @param s the string\n     * @return the integer value represented by the argument in decimal.","sourceCodeStart":1,"sourceCodeEnd":30,"githubUrl":"https://github.com/TheAlgorithms/Java/blob/fdfb9a395b310167a66bd29e311e36e0e3e9b964/src/main/java/com/thealgorithms/maths/ParseInteger.java#L1-L30","documentation":"Thrown by ParseInteger.checkInput when the input string s is empty (s.isEmpty()). An empty string has no digits and cannot represent an integer, so parsing would be meaningless. This is the second guard, after the null check.","triggerScenarios":"Calling the public parse method with \"\" — e.g., ParseInteger.parse(\"\").","commonSituations":"User submitted an empty form field; a CSV/regex split produced an empty token; a default value of \"\" was never overwritten; trimming whitespace left an empty string.","solutions":["Validate that the trimmed string is non-empty before parsing: if (s == null || s.isBlank()) handle accordingly.","Treat empty input as a domain-level missing value rather than passing it through to parse.","Sanitize upstream: filter out empty tokens from splits before iteration."],"exampleFix":"// before\nint v = ParseInteger.parse(raw);\n\n// after\nif (raw == null || raw.isBlank()) {\n    throw new IllegalArgumentException(\"raw is missing\");\n}\nint v = ParseInteger.parse(raw.trim());","handlingStrategy":"validation","validationCode":"if (s == null || s.isBlank()) {\n    throw new IllegalArgumentException(\"input is missing\");\n}\nint v = ParseInteger.parse(s.trim());","typeGuard":null,"tryCatchPattern":"try {\n    int v = ParseInteger.parse(s);\n} catch (NumberFormatException e) {\n    throw new IllegalArgumentException(\"invalid integer input: \" + s, e);\n}","preventionTips":["Trim and check for blank input before parsing.","Filter empty tokens from split results before iteration.","Treat empty input as a domain-level missing value rather than passing it through."],"tags":["math","parsing","empty-string","number-format"],"backgroundTag":null,"analyzedSha":"fdfb9a395b310167a66bd29e311e36e0e3e9b964","analyzedAt":"2026-08-13T23:36:13.315Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}