{"record":{"id":"f2541155bcf2371f","repo":"stanfordnlp/CoreNLP","slug":"input-must-be-sorted","errorCode":null,"errorMessage":"input must be sorted!","messagePattern":"input must be sorted!","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/sequences/Clique.java","lineNumber":114,"sourceCode":"    return valueOfHelper(ri);\n  }\n\n  /** This version assumes relativeIndices array no longer needs to\n   *  be copied. Further it is assumed that it has already been\n   *  checked or assured by construction that relativeIndices\n   *  is sorted.\n   */\n  private static Clique valueOfHelper(int[] relativeIndices) {\n    // if clique already exists, return that one\n    Clique c = new Clique(relativeIndices);\n    return intern(c);\n  }\n\n  /** Parameter validity check. */\n  private static void checkSorted(int[] sorted) {\n    for (int i = 0; i < sorted.length-1; i++) {\n      if (sorted[i] > sorted[i+1]) {\n        throw new RuntimeException(\"input must be sorted!\");\n      }\n    }\n  }\n\n  /**\n   * Convenience method for finding the most far left\n   * relative index.\n   */\n  public int maxLeft() { return relativeIndices[0]; }\n\n  /**\n   * Convenience method for finding the most far right\n   * relative index.\n   */\n  public int maxRight() { return relativeIndices[relativeIndices.length-1]; }\n\n  /** The number of nodes in the clique. */\n  public int size() { return relativeIndices.length; }","sourceCodeStart":96,"sourceCodeEnd":132,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/sequences/Clique.java#L96-L132","documentation":"Clique.valueOf(int[] input) requires its argument to be in non-decreasing order because the clique's cached identity depends on sorted domain indices. checkSorted scans the array and throws RuntimeException('input must be sorted!') on any descending pair.","triggerScenarios":"Calling Clique.valueOf with an int array where some element is greater than its successor, e.g. new int[]{2,1} or unsorted variable indices built dynamically, at Clique.java:114 (via valueOf).","commonSituations":"Building clique indices by hand or concatenating offsets without sorting; bugs in feature-index construction in sequence models (e.g. CRF feature extraction code that assumes pre-sorted input).","solutions":["Sort the array before calling Clique.valueOf, e.g. Arrays.sort(indices).","Fix the producing code so clique/variable indices are generated in ascending order.","If duplicates/order semantics matter, dedupe then sort."],"exampleFix":"// before\nClique c = Clique.valueOf(new int[]{3, 1, 2});\n// after\nint[] idx = new int[]{3, 1, 2};\njava.util.Arrays.sort(idx);\nClique c = Clique.valueOf(idx);","handlingStrategy":"validation","validationCode":"// assert sorted before Clique.valueOf\nstatic void assertSorted(int[] a) {\n  for (int i = 0; i < a.length - 1; i++)\n    if (a[i] > a[i+1]) throw new IllegalArgumentException(\"unsorted at \" + i);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Arrays.sort(...) every index array before Clique.valueOf.","Generate variable indices in ascending order by construction.","Add a debug assertion in feature-extraction code that produces cliques."],"tags":["java","stanford-corenlp","crf","invariant"],"backgroundTag":"internal-invariant-violation","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"}