stanfordnlp/CoreNLP · error · IllegalArgumentException
Constructor argument not valid list of number ranges
Error message
Constructor argument not valid list of number ranges: <ranges>
What it means
The constructor wraps its whole range-parsing loop in a catch-all; any Exception while parsing (NumberFormatException from a non-integer token, ArrayIndexOutOfBounds from an empty token) is rethrown as this IllegalArgumentException with the original ranges string and cause attached.
Solutions
- Inspect the cause (getCause()) to find the offending token and fix the ranges string to only contain integers and hyphens
- Pre-validate with a regex \\d+(-\\d+)?(,\\s*\\d+(-\\d+)?)* and reject bad input with your own message
- Trim/split defensively: strip spaces, drop empty tokens before constructing the filter
Example fix
// before
new NumberRangesFileFilter("1, 2-5, ,8", false); // empty token -> NumberFormatException
// after
String ranges = "1, 2-5, ,8";
if (!ranges.matches("\\d+(-\\d+)?(,\\s*\\d+(-\\d+)?)*")) {
throw new IllegalArgumentException("Bad ranges: " + ranges);
}
new NumberRangesFileFilter(ranges, false); Defensive patterns
Strategy: try-catch
Validate before calling
if (!ranges.matches("\\d+(-\\d+)?(,\\s*\\d+(-\\d+)?)*")) throw new IllegalArgumentException("Bad ranges: " + ranges); Try / catch
try { f = new NumberRangesFileFilter(ranges, recurse); } catch (IllegalArgumentException e) { log.severe("Bad ranges '" + ranges + "': " + e.getCause()); throw e; } Prevention
- Always check getCause() to identify the bad token
- Trim and drop empty tokens after splitting on commas
- Validate user/config-supplied range strings before parsing
When it happens
Trigger: new NumberRangesFileFilter("1,a-5,,20", false) — any token that fails Integer.parseInt or is empty after trimming.
Common situations: Config/property values with typos or whitespace artifacts, empty entries from trailing commas, format mistakes like "1 to 5" instead of "1-5".
Understand the failure class
Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.
Related errors
- Bad number put into wordToNumber. Word is: \"" + input +…
- Error in wordToNumber function.
- Bad number put into wordToNumber. Word is: \"" + curPart +…
- Too many columns: / (offset: )
- Too few columns: / (offset: )
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/94d8535305e16638.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/io/NumberRangesFileFilter.java:75
String[] ra = ranges.split(",");
for (String range : ra) {
String[] one = range.split("-");
if (one.length > 2) {
throw new IllegalArgumentException("Constructor argument not valid list of number ranges (too many hyphens): ");
} else {
int low = Integer.parseInt(one[0].trim());
int high;
if (one.length == 2) {
high = Integer.parseInt(one[1].trim());
} else {
high = low;
}
Pair<Integer, Integer> p = new Pair<>(Integer.valueOf(low), Integer.valueOf(high));
this.ranges.add(p);
}
}
} catch (Exception e) {
throw new IllegalArgumentException("Constructor argument not valid list of number ranges: " + ranges, e);
}
}
/**
* Checks whether a file satisfies the number range selection filter.
* The test is evaluated based on the rightmost natural number found in
* the filename string (proper, not including directories in a path).
*
* @param file The file
* @return true If the file is within the ranges filtered for
*/
public boolean accept(File file) {
if (file.isDirectory()) {
return recursively;
} else {
String filename = file.getName();
return accept(filename);View on GitHub (pinned to 1b7edd19c4)