{"record":{"id":"2dcac6024d61a00c","repo":"stanfordnlp/CoreNLP","slug":"unknown-value-for-span-values-1","errorCode":null,"errorMessage":"Unknown value for span: ${values[1]}","messagePattern":"Unknown value for span: (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/ie/machinereading/structure/Span.java","lineNumber":70,"sourceCode":"      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;\n  }\n  \n  @Override\n  public int hashCode() {","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/ie/machinereading/structure/Span.java#L52-L88","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nSpan s = Span.fromValues(tokenStart, tokenEnd); // tokenEnd may be a String while tokenStart is an Integer -> throws\n// after\nSpan s = Span.fromValues(Integer.parseInt(String.valueOf(tokenStart)), Integer.parseInt(String.valueOf(tokenEnd)));","handlingStrategy":"validation","validationCode":"static Span safeFromValues(Object a, Object b) {\n  if (a == null || b == null) throw new IllegalArgumentException(\"Span endpoints must be non-null\");\n  if (!(a instanceof Number || a instanceof String) || !(b instanceof Number || b instanceof String))\n    throw new IllegalArgumentException(\"Span endpoints must be Number or numeric String\");\n  return Span.fromValues(Integer.parseInt(String.valueOf(a)), Integer.parseInt(String.valueOf(b)));\n}","typeGuard":"static boolean isSpanEndpoint(Object o) { return o instanceof Number || (o instanceof String && ((String) o).matches(\"-?\\\\d+\")); }","tryCatchPattern":"try { return Span.fromValues(v1, v2); } catch (IllegalArgumentException e) { log.warn(\"Bad span endpoints: \" + e.getMessage()); return null; }","preventionTips":["Always pass Integer endpoints to fromValues","Null-check Object[] inputs before span construction","Convert strings to ints at the deserialization boundary"],"tags":["java","argument-validation","span"],"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"}