stanfordnlp/CoreNLP · error · RuntimeException
input must be sorted!
Error message
input must be sorted!
What it means
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.
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.
Example fix
// before
Clique c = Clique.valueOf(new int[]{3, 1, 2});
// after
int[] idx = new int[]{3, 1, 2};
java.util.Arrays.sort(idx);
Clique c = Clique.valueOf(idx); Defensive patterns
Strategy: validation
Validate before calling
// assert sorted before Clique.valueOf
static void assertSorted(int[] a) {
for (int i = 0; i < a.length - 1; i++)
if (a[i] > a[i+1]) throw new IllegalArgumentException("unsorted at " + i);
} Prevention
- 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.
When it happens
Trigger: 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).
Common situations: 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).
Understand the failure class
Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.
Related errors
- node cliqueFeatures[n]=
- edge cliqueFeatures[n]=
- linearConstraints.length (
- oldTag starts with B, entity at position should not be null
- Unknown feature type " + feature
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/f2541155bcf2371f.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/sequences/Clique.java:114
return valueOfHelper(ri);
}
/** This version assumes relativeIndices array no longer needs to
* be copied. Further it is assumed that it has already been
* checked or assured by construction that relativeIndices
* is sorted.
*/
private static Clique valueOfHelper(int[] relativeIndices) {
// if clique already exists, return that one
Clique c = new Clique(relativeIndices);
return intern(c);
}
/** Parameter validity check. */
private static void checkSorted(int[] sorted) {
for (int i = 0; i < sorted.length-1; i++) {
if (sorted[i] > sorted[i+1]) {
throw new RuntimeException("input must be sorted!");
}
}
}
/**
* Convenience method for finding the most far left
* relative index.
*/
public int maxLeft() { return relativeIndices[0]; }
/**
* Convenience method for finding the most far right
* relative index.
*/
public int maxRight() { return relativeIndices[relativeIndices.length-1]; }
/** The number of nodes in the clique. */
public int size() { return relativeIndices.length; }View on GitHub (pinned to 1b7edd19c4)