{"record":{"id":"4681a42305efbef9","repo":"stanfordnlp/CoreNLP","slug":"fromvalues-must-take-an-array-with-2-elements","errorCode":null,"errorMessage":"fromValues() must take an array with 2 elements","messagePattern":"fromValues\\(\\) must take an array with 2 elements","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/ie/machinereading/structure/Span.java","lineNumber":62,"sourceCode":"  }\n  \n  /**\n   * Safe way to construct Spans if you're not sure which value is higher.\n   */\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","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/ie/machinereading/structure/Span.java#L44-L80","documentation":"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.","triggerScenarios":"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.","commonSituations":"Refactoring code that changed span arity, passing a token list directly to fromValues, generic code that forwards a values array of arbitrary length.","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."],"exampleFix":"// before\nSpan s = Span.fromValues(start, end, label);\n// after\nSpan s = Span.fromValues(start, end);","handlingStrategy":"validation","validationCode":"if (values == null || (values.length != 1 && values.length != 2)) {\n  throw new IllegalArgumentException(\"Span.fromValues requires 1 or 2 values, got \" + (values == null ? 0 : values.length));\n}","typeGuard":null,"tryCatchPattern":"try { Span s = Span.fromValues(vals); } catch (IllegalArgumentException e) { /* fix arity at call site */ }","preventionTips":["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."],"tags":["java","stanford-nlp","span"],"backgroundTag":"missing-required-argument","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"}