{"record":{"id":"c6709cdb83f26fce","repo":"TheAlgorithms/Java","slug":"input-parameter-must-not-be-null","errorCode":null,"errorMessage":"Input parameter must not be null!","messagePattern":"Input parameter must not be null!","errorType":"exception","errorClass":"NumberFormatException","httpStatus":null,"severity":"error","filePath":"src/main/java/com/thealgorithms/maths/ParseInteger.java","lineNumber":9,"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","sourceCodeStart":1,"sourceCodeEnd":27,"githubUrl":"https://github.com/TheAlgorithms/Java/blob/fdfb9a395b310167a66bd29e311e36e0e3e9b964/src/main/java/com/thealgorithms/maths/ParseInteger.java#L1-L27","documentation":"Thrown by ParseInteger.checkInput (a private helper) when the input string s is null. The method deliberately throws NumberFormatException (mirroring Integer.parseInt semantics) so callers using standard numeric-parsing exception handling are consistent. The null check is the first guard before any string operation.","triggerScenarios":"Calling the public parse method (which delegates to checkInput) with a null String argument — e.g., ParseInteger's parse(null).","commonSituations":"JSON/CSV field mapped to null due to missing key; Optional/path that resolved to null; variable default-initialized to null and never assigned; refactoring that removed an intermediate null-check.","solutions":["Null-check at the source: use Objects.requireNonNull(s, ...) or an explicit if (s == null) guard.","Coalesce null to a default or reject the request before calling parse.","Use Optional.ofNullable(s).map(ParseInteger::parse) to handle absence explicitly."],"exampleFix":"// before\nint v = ParseInteger.parse(input);\n\n// after\nInteger v = input == null ? null : ParseInteger.parse(input);\n// or reject:\nObjects.requireNonNull(input, \"input must not be null\");\nint v = ParseInteger.parse(input);","handlingStrategy":"validation","validationCode":"Objects.requireNonNull(s, \"input must not be null\");\nint v = ParseInteger.parse(s);","typeGuard":null,"tryCatchPattern":"try {\n    int v = ParseInteger.parse(s);\n} catch (NumberFormatException e) {\n    // handle null, empty, or malformed input uniformly\n    throw new IllegalArgumentException(\"invalid integer input: \" + s, e);\n}","preventionTips":["Null-check at the source (parser, deserializer) before calling parse.","Prefer Optional.ofNullable(s).map(ParseInteger::parse) for absence handling.","Treat null numeric input as a missing-value condition, not a parse failure."],"tags":["math","parsing","null-argument","number-format"],"backgroundTag":null,"analyzedSha":"fdfb9a395b310167a66bd29e311e36e0e3e9b964","analyzedAt":"2026-08-13T23:36:13.315Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}