stanfordnlp/CoreNLP · error · IllegalArgumentException

Unknown value for span

Error message

Unknown value for span: ${values[0]}

What it means

When converting fromValues arguments to ints, each value must be a Number or a numeric String. Any other object type for values[0] (or values[1]) throws this IllegalArgumentException naming the offending object.

Solutions

  1. Pass ints (or numeric values/Strings) for the span endpoints: Span.fromValues(start, end).
  2. Extract the index from your object first (e.g. token.index()) before calling fromValues.
  3. Cast/convert non-numeric values at the call site.
  4. Use the Span(int, int) constructor directly when values are already ints.

Example fix

// before
Span s = Span.fromValues(token, other);
// after
Span s = Span.fromValues(token.index(), other.index());
Defensive patterns

Strategy: type-guard

Validate before calling

boolean ok = (v instanceof Number) || (v instanceof String && v.toString().matches("-?\\d+"));
if (!ok) throw new IllegalArgumentException("span endpoint must be Number or numeric String");

Type guard

boolean isSpanValue(Object v) { return v instanceof Number || (v instanceof String && ((String) v).matches("-?\\d+")); }

Try / catch

try { Span s = Span.fromValues(v1, v2); } catch (IllegalArgumentException e) { /* convert v1/v2 to int first */ }

Prevention

When it happens

Trigger: Calling Span.fromValues(someObject, ...) where someObject is neither Number nor String — e.g. passing an Integer boxed in an unusual type is fine, but passing a List, Token, or Label object throws; also passing non-numeric Strings triggers it indirectly via NumberFormatException, while arbitrary objects hit this branch directly.

Common situations: Passing token or entity objects instead of their indices, forwarding generic Object varargs from reflection-driven code, mixing typed and untyped span construction APIs.

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


AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10). Data as JSON: /api/errors/18760ee8f4f89f3d. Report an issue: GitHub.

Appendix: source

Thrown at src/edu/stanford/nlp/ie/machinereading/structure/Span.java:66

   */
  @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; }
  
  @Override
  public boolean equals(Object other) {
    if(! (other instanceof Span)) return false;
    Span otherSpan = (Span) other;
    return start == otherSpan.start && end == otherSpan.end;

View on GitHub (pinned to 1b7edd19c4)