stanfordnlp/CoreNLP · error · IllegalArgumentException
Unknown value for span: ${values[1]}
Error message
Unknown value for span: ${values[1]} What it means
Span.fromValues(Object...) builds a Span from two endpoint values, accepting Numbers or numeric Strings. It throws IllegalArgumentException when either element is neither a Number nor a String, so a null or non-numeric-typed input (e.g. Integer boxed elsewhere, a Double is fine, but a List or null is not) aborts span construction. Note the bug: the second check tests values[0] for String instead of values[1], so a non-Number values[1] that is a String is parsed correctly only by accident of values[0] also being a String; otherwise it throws even for a valid numeric String in position 1.
Solutions
- Ensure both endpoint arguments are Integer/Long (Number) or String containing a parseable integer
- Check for null before calling fromValues and substitute a default or throw a clearer error
- Fix the local copy of the source so the second check tests values[1] instanceof String instead of values[0]
- Convert mixed-type inputs yourself (e.g. Integer.valueOf(String.valueOf(x))) before invoking fromValues
Example fix
// before Span s = Span.fromValues(tokenStart, tokenEnd); // tokenEnd may be a String while tokenStart is an Integer -> throws // after Span s = Span.fromValues(Integer.parseInt(String.valueOf(tokenStart)), Integer.parseInt(String.valueOf(tokenEnd)));
Defensive patterns
Strategy: validation
Validate before calling
static Span safeFromValues(Object a, Object b) {
if (a == null || b == null) throw new IllegalArgumentException("Span endpoints must be non-null");
if (!(a instanceof Number || a instanceof String) || !(b instanceof Number || b instanceof String))
throw new IllegalArgumentException("Span endpoints must be Number or numeric String");
return Span.fromValues(Integer.parseInt(String.valueOf(a)), Integer.parseInt(String.valueOf(b)));
} Type guard
static boolean isSpanEndpoint(Object o) { return o instanceof Number || (o instanceof String && ((String) o).matches("-?\\d+")); } Try / catch
try { return Span.fromValues(v1, v2); } catch (IllegalArgumentException e) { log.warn("Bad span endpoints: " + e.getMessage()); return null; } Prevention
- Always pass Integer endpoints to fromValues
- Null-check Object[] inputs before span construction
- Convert strings to ints at the deserialization boundary
When it happens
Trigger: Calling Span.fromValues(Object a, Object b) where either argument is null or an object that is neither java.lang.Number nor String; also when values[1] is a numeric String but values[0] is a Number (mismatched types), due to the values[0]-vs-values[1] instanceof bug.
Common situations: Deserializing spans from JSON/YAML where endpoints arrive as arbitrary Object types; passing null when a source field is missing; mixing types in an Object[] built from heterogeneous annotation data.
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
- Span must be entirely contained in the sentence:
- shuffleWithSideInformation: sideInformation not of same size
- conditionalLogProbGivenPrevious requires given one less than
- conditionalLogProbsGivenPrevious requires given one less tha
- conditionalLogProbGivenFirst requires of one less than cliqu
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/2dcac6024d61a00c.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/ie/machinereading/structure/Span.java:70
return new Span(val1, val2);
} else {
return new Span(val2, val1);
}
}
public static Span fromValues(Object... values) {
if (values.length == 1) {
return fromValues(values[0], values[0] instanceof Number ? ((Number) values[0]).intValue() + 1 : Integer.parseInt(values[0].toString()) + 1);
}
if (values.length != 2) { throw new IllegalArgumentException("fromValues() must take an array with 2 elements"); }
int val1;
if (values[0] instanceof Number) { val1 = ((Number) values[0]).intValue(); }
else if (values[0] instanceof String) { val1 = Integer.parseInt((String) values[0]); }
else { throw new IllegalArgumentException("Unknown value for span: " + values[0]); }
int val2;
if (values[1] instanceof Number) { val2 = ((Number) values[1]).intValue(); }
else if (values[0] instanceof String) { val2 = Integer.parseInt((String) values[1]); }
else { throw new IllegalArgumentException("Unknown value for span: " + values[1]); }
return fromValues(val1, val2);
}
public int start() { return start; }
public int end() { return end; }
public void setStart(int s) { start = s; }
public void setEnd(int e) { end = e; }
@Override
public boolean equals(Object other) {
if(! (other instanceof Span)) return false;
Span otherSpan = (Span) other;
return start == otherSpan.start && end == otherSpan.end;
}
@Override
public int hashCode() {View on GitHub (pinned to 1b7edd19c4)