stanfordnlp/CoreNLP · error · IllegalArgumentException
fromValues() must take an array with 2 elements
Error message
fromValues() must take an array with 2 elements
What it means
Span.fromValues(Object... values) accepts either exactly one value (creating a one-token span) or exactly two values (start, end). Any other arity throws this IllegalArgumentException because a span cannot be defined from 0 or 3+ values.
Solutions
- Call fromValues with exactly one or two arguments; fix the call site arity.
- If you have 3+ values, extract only the start/end pair you need.
- For one-token spans pass a single value (the library computes end = value + 1).
- Add a caller-side length check on the values array before invoking.
Example fix
// before Span s = Span.fromValues(start, end, label); // after Span s = Span.fromValues(start, end);
Defensive patterns
Strategy: validation
Validate before calling
if (values == null || (values.length != 1 && values.length != 2)) {
throw new IllegalArgumentException("Span.fromValues requires 1 or 2 values, got " + (values == null ? 0 : values.length));
} Try / catch
try { Span s = Span.fromValues(vals); } catch (IllegalArgumentException e) { /* fix arity at call site */ } Prevention
- Always call fromValues with exactly one (single token) or two (start,end) arguments.
- Extract start/end explicitly instead of forwarding whole arrays of values.
- Prefer the typed Span(int, int) constructor when arity is known.
When it happens
Trigger: Calling Span.fromValues() with an empty varargs array, or accidentally passing 3+ arguments (e.g. start, end, plus an extra label), or spreading an array/list of wrong length.
Common situations: Refactoring code that changed span arity, passing a token list directly to fromValues, generic code that forwards a values array of arbitrary length.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- Unknown value for span
- Not sure if RVFDataset runs correctly in this method…
- minValue for feature
- maxValue for feature
- datum
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/4681a42305efbef9.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/ie/machinereading/structure/Span.java:62
}
/**
* Safe way to construct Spans if you're not sure which value is higher.
*/
@SuppressWarnings("UnusedDeclaration")
public static Span fromValues(int val1, int val2) {
if (val1 <= val2) {
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; }
@OverrideView on GitHub (pinned to 1b7edd19c4)