stanfordnlp/CoreNLP · error · IllegalArgumentException
Invalid interval
Error message
Invalid interval: ${a},${b} What it means
Interval's protected constructor validates that endpoint a does not compare greater than endpoint b. Passing endpoints in the wrong order throws IllegalArgumentException with both endpoints in the message.
Solutions
- Ensure a <= b per the element's natural ordering before constructing
- Normalize with Interval.toInterval(a,b) or the ordered factory, which returns null / reorders for invalid inputs rather than throwing
- Check the compareTo implementation of your endpoint type for correctness
Example fix
// before Interval<Integer> iv = new Interval<>(5, 2); // throws // after Interval<Integer> iv = (5 <= 2) ? new Interval<>(5, 2) : new Interval<>(2, 5);
Defensive patterns
Strategy: validation
Validate before calling
if (a.compareTo(b) > 0) { E tmp = a; a = b; b = tmp; } Type guard
boolean validInterval(Comparable<?> a, Comparable<?> b) { return a.compareTo(b) <= 0; } Try / catch
try { Interval<E> iv = new Interval<>(a, b, flags); } catch (IllegalArgumentException e) { /* swap or reject endpoints */ } Prevention
- Order endpoints (min, max) before constructing intervals
- Use the public factory methods that handle unordered inputs
- Test compareTo implementations of custom endpoint types
When it happens
Trigger: Constructing an Interval (directly via the protected constructor or subclasses/relative-interval paths) where a.compareTo(b) > 0, i.e. start after end.
Common situations: Swapped arguments when creating spans; computing endpoints dynamically (e.g. min/max of token offsets) and getting them reversed; using custom Comparables whose compareTo is inconsistent.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- Attempt to open file with null name
- Bad arguments: " + x + " and " + lambda
- Collection elements must be Files or Strings
- conditionalLogProbGivenFirst requires of one less than…
- conditionalLogProbGivenNext requires given one less than…
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/aea22052247ebd1f.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/util/Interval.java:330
*/
public static final int REL_FLAGS_INTERVAL_UNKNOWN = 0x00770000;
public static final int REL_FLAGS_INTERVAL_ALMOST_SAME = 0x01000000;
public static final int REL_FLAGS_INTERVAL_ALMOST_BEFORE = 0x01000000;
public static final int REL_FLAGS_INTERVAL_ALMOST_AFTER = 0x01000000;
// public final static int REL_FLAGS_INTERVAL_ALMOST_OVERLAP = 0x10000000;
// public final static int REL_FLAGS_INTERVAL_ALMOST_INSIDE = 0x20000000;
// public final static int REL_FLAGS_INTERVAL_ALMOST_CONTAIN = 0x40000000;
public static final int REL_FLAGS_INTERVAL_FUZZY = 0x80000000;
protected Interval(E a, E b, int flags) {
super(a,b);
this.flags = flags;
int comp = a.compareTo(b);
if (comp > 0) {
throw new IllegalArgumentException("Invalid interval: " + a + "," + b);
}
}
/**
* Create an interval with the specified endpoints in the specified order.
* Returns null if a does not come before b (invalid interval).
*
* @param a start endpoints
* @param b end endpoint
* @param <E> type of the interval endpoints
* @return Interval with endpoints in specified order, null if a does not come before b
*/
public static <E extends Comparable<E>> Interval<E> toInterval(E a, E b) {
return toInterval(a,b,0);
}
/**
* Create an interval with the specified endpoints in the specified order,View on GitHub (pinned to 1b7edd19c4)