stanfordnlp/CoreNLP · error · IllegalArgumentException
Constructor argument not valid list of number ranges (too…
Error message
Constructor argument not valid list of number ranges (too many hyphens):
What it means
NumberRangesFileFilter parses a comma-separated string of number ranges like "1-5,20,100-200". Each comma-separated token may contain at most one hyphen; a token with more than one hyphen cannot be a valid range, so the constructor throws this IllegalArgumentException. The message notably omits the offending input string.
Solutions
- Remove the extra hyphen so each token is either "N" or "N-M" with non-negative integers
- If negative bounds are needed, preprocess the string yourself and pass absolute values or a custom filter
- Validate the ranges string with a regex like \\d+(-\\d+)?(,\\d+(-\\d+)?)* before constructing
Example fix
// before
new NumberRangesFileFilter("1-2-5", false);
// after
new NumberRangesFileFilter("1-5", false); Defensive patterns
Strategy: validation
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) { if (e.getMessage().contains("too many hyphens")) { /* fix ranges string */ } else throw e; } Prevention
- Regex-validate range strings before constructing
- Avoid negative numbers in range specs
- Sanitize concatenated config values for stray hyphens
When it happens
Trigger: new NumberRangesFileFilter("1-2-3", false) or any ranges string where a comma-separated token splits on '-' into more than 2 pieces (e.g. negative-number-looking tokens like "-1-5").
Common situations: Negative range endpoints ("-10--1"), typos with extra hyphens, filenames/config values built by string concatenation that leaked an extra '-'.
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
- Array lengths don't match
- Cannot parse Trilean from string: " + value
- Constructor argument not valid list of number ranges
- Too few columns: / (offset: )
- Too many columns: / (offset: )
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/d477820809414fb4.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/io/NumberRangesFileFilter.java:61
/**
* Sets up a NumberRangesFileFilter by specifying the ranges of numbers
* to accept, and whether to also traverse
* folders for recursive search.
*
* @param ranges The ranges of numbers to accept (see class documentation)
* @param recurse Whether to go into subfolders
* @throws IllegalArgumentException If the String ranges does not
* contain a suitable ranges format
*/
public NumberRangesFileFilter(String ranges, boolean recurse) {
recursively = recurse;
try {
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);
}
}
View on GitHub (pinned to 1b7edd19c4)