{"record":{"id":"18760ee8f4f89f3d","repo":"stanfordnlp/CoreNLP","slug":"unknown-value-for-span-values-0","errorCode":null,"errorMessage":"Unknown value for span: ${values[0]}","messagePattern":"Unknown value for span: (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/ie/machinereading/structure/Span.java","lineNumber":66,"sourceCode":"   */\n  @SuppressWarnings(\"UnusedDeclaration\")\n  public static Span fromValues(int val1, int val2) {\n    if (val1 <= val2) {\n      return new Span(val1, val2);\n    } else {\n      return new Span(val2, val1);\n    }\n  }\n\n  public static Span fromValues(Object... values) {\n    if (values.length == 1) {\n      return fromValues(values[0], values[0] instanceof Number ? ((Number) values[0]).intValue() + 1 : Integer.parseInt(values[0].toString()) + 1);\n    }\n    if (values.length != 2) { throw new IllegalArgumentException(\"fromValues() must take an array with 2 elements\"); }\n    int val1;\n    if (values[0] instanceof Number) { val1 = ((Number) values[0]).intValue(); }\n    else if (values[0] instanceof String) { val1 = Integer.parseInt((String) values[0]); }\n    else { throw new IllegalArgumentException(\"Unknown value for span: \" + values[0]); }\n    int val2;\n    if (values[1] instanceof Number) { val2 = ((Number) values[1]).intValue(); }\n    else if (values[0] instanceof String) { val2 = Integer.parseInt((String) values[1]); }\n    else { throw new IllegalArgumentException(\"Unknown value for span: \" + values[1]); }\n    return fromValues(val1, val2);\n  }\n\n  public int start() { return start; }\n  public int end() { return end; }\n  \n  public void setStart(int s) { start = s; }\n  public void setEnd(int e) { end = e; }\n  \n  @Override\n  public boolean equals(Object other) {\n    if(! (other instanceof Span)) return false;\n    Span otherSpan = (Span) other;\n    return start == otherSpan.start && end == otherSpan.end;","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/ie/machinereading/structure/Span.java#L48-L84","documentation":"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.","triggerScenarios":"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.","commonSituations":"Passing token or entity objects instead of their indices, forwarding generic Object varargs from reflection-driven code, mixing typed and untyped span construction APIs.","solutions":["Pass ints (or numeric values/Strings) for the span endpoints: Span.fromValues(start, end).","Extract the index from your object first (e.g. token.index()) before calling fromValues.","Cast/convert non-numeric values at the call site.","Use the Span(int, int) constructor directly when values are already ints."],"exampleFix":"// before\nSpan s = Span.fromValues(token, other);\n// after\nSpan s = Span.fromValues(token.index(), other.index());","handlingStrategy":"type-guard","validationCode":"boolean ok = (v instanceof Number) || (v instanceof String && v.toString().matches(\"-?\\\\d+\"));\nif (!ok) throw new IllegalArgumentException(\"span endpoint must be Number or numeric String\");","typeGuard":"boolean isSpanValue(Object v) { return v instanceof Number || (v instanceof String && ((String) v).matches(\"-?\\\\d+\")); }","tryCatchPattern":"try { Span s = Span.fromValues(v1, v2); } catch (IllegalArgumentException e) { /* convert v1/v2 to int first */ }","preventionTips":["Pass ints or numeric strings as span endpoints.","Extract numeric indices from token/label objects before constructing spans.","Use Span(int, int) directly to get compile-time type checking."],"tags":["java","stanford-nlp","span","type-mismatch"],"backgroundTag":"invalid-argument-value","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}