TheAlgorithms/Java · error · NumberFormatException
Input parameter must not be empty!
Error message
Input parameter must not be empty!
What it means
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.
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.
Example fix
// before
int v = ParseInteger.parse(raw);
// after
if (raw == null || raw.isBlank()) {
throw new IllegalArgumentException("raw is missing");
}
int v = ParseInteger.parse(raw.trim()); Defensive patterns
Strategy: validation
Validate before calling
if (s == null || s.isBlank()) {
throw new IllegalArgumentException("input is missing");
}
int v = ParseInteger.parse(s.trim()); Try / catch
try {
int v = ParseInteger.parse(s);
} catch (NumberFormatException e) {
throw new IllegalArgumentException("invalid integer input: " + s, e);
} Prevention
- 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.
When it happens
Trigger: Calling the public parse method with "" — e.g., ParseInteger.parse("").
Common situations: 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.
Related errors
- Input parameter must not be null!
- Input parameter of incorrect format:
- Input string must be a valid integer
- additivePersistence() does not accept negative values
- All side lengths must be positive
AI-assisted analysis of TheAlgorithms/Java@fdfb9a395b (2026-08-13).
Data as JSON: /api/errors/2b80aea5c56cd4db.
Report an issue: GitHub.
Appendix: source
Thrown at src/main/java/com/thealgorithms/maths/ParseInteger.java:12
package com.thealgorithms.maths;
public final class ParseInteger {
private ParseInteger() {
}
private static void checkInput(final String s) {
if (s == null) {
throw new NumberFormatException("Input parameter must not be null!");
}
if (s.isEmpty()) {
throw new NumberFormatException("Input parameter must not be empty!");
}
}
private static void checkDigitAt(final String s, final int pos) {
if (!Character.isDigit(s.charAt(pos))) {
throw new NumberFormatException("Input parameter of incorrect format: " + s);
}
}
private static int digitToInt(final char digit) {
return digit - '0';
}
/**
* Parse a string to integer
*
* @param s the string
* @return the integer value represented by the argument in decimal.View on GitHub (pinned to fdfb9a395b)