{"record":{"id":"aea22052247ebd1f","repo":"stanfordnlp/CoreNLP","slug":"invalid-interval-a-b","errorCode":null,"errorMessage":"Invalid interval: ${a},${b}","messagePattern":"Invalid interval: (.+?),(.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/util/Interval.java","lineNumber":330,"sourceCode":"   */\n  public static final int REL_FLAGS_INTERVAL_UNKNOWN = 0x00770000;\n\n  public static final int REL_FLAGS_INTERVAL_ALMOST_SAME = 0x01000000;\n  public static final int REL_FLAGS_INTERVAL_ALMOST_BEFORE = 0x01000000;\n  public static final int REL_FLAGS_INTERVAL_ALMOST_AFTER = 0x01000000;\n\n//  public final static int REL_FLAGS_INTERVAL_ALMOST_OVERLAP = 0x10000000;\n//  public final static int REL_FLAGS_INTERVAL_ALMOST_INSIDE = 0x20000000;\n//  public final static int REL_FLAGS_INTERVAL_ALMOST_CONTAIN = 0x40000000;\n\n  public static final int REL_FLAGS_INTERVAL_FUZZY = 0x80000000;\n\n  protected Interval(E a, E b, int flags) {\n    super(a,b);\n    this.flags = flags;\n    int comp = a.compareTo(b);\n    if (comp > 0) {\n      throw new IllegalArgumentException(\"Invalid interval: \" + a + \",\" + b);\n    }\n  }\n\n  /**\n   * Create an interval with the specified endpoints in the specified order.\n   * Returns null if a does not come before b (invalid interval).\n   *\n   * @param a start endpoints\n   * @param b end endpoint\n   * @param <E> type of the interval endpoints\n   * @return Interval with endpoints in specified order, null if a does not come before b\n   */\n  public static <E extends Comparable<E>> Interval<E> toInterval(E a, E b) {\n    return toInterval(a,b,0);\n  }\n\n  /**\n   * Create an interval with the specified endpoints in the specified order,","sourceCodeStart":312,"sourceCodeEnd":348,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/util/Interval.java#L312-L348","documentation":"Interval's protected constructor validates that endpoint a does not compare greater than endpoint b. Passing endpoints in the wrong order throws IllegalArgumentException with both endpoints in the message.","triggerScenarios":"Constructing an Interval (directly via the protected constructor or subclasses/relative-interval paths) where a.compareTo(b) > 0, i.e. start after end.","commonSituations":"Swapped arguments when creating spans; computing endpoints dynamically (e.g. min/max of token offsets) and getting them reversed; using custom Comparables whose compareTo is inconsistent.","solutions":["Ensure a <= b per the element's natural ordering before constructing","Normalize with Interval.toInterval(a,b) or the ordered factory, which returns null / reorders for invalid inputs rather than throwing","Check the compareTo implementation of your endpoint type for correctness"],"exampleFix":"// before\nInterval<Integer> iv = new Interval<>(5, 2); // throws\n// after\nInterval<Integer> iv = (5 <= 2) ? new Interval<>(5, 2) : new Interval<>(2, 5);","handlingStrategy":"validation","validationCode":"if (a.compareTo(b) > 0) { E tmp = a; a = b; b = tmp; }","typeGuard":"boolean validInterval(Comparable<?> a, Comparable<?> b) { return a.compareTo(b) <= 0; }","tryCatchPattern":"try { Interval<E> iv = new Interval<>(a, b, flags); } catch (IllegalArgumentException e) { /* swap or reject endpoints */ }","preventionTips":["Order endpoints (min, max) before constructing intervals","Use the public factory methods that handle unordered inputs","Test compareTo implementations of custom endpoint types"],"tags":["interval","argument-validation","ordering"],"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-17T15:17:12.973Z"}