stanfordnlp/CoreNLP · error · IllegalArgumentException
Index array length
Error message
Index array length
What it means
Alignment.makeFromIndexArray throws IllegalArgumentException when the length of the index array does not equal hypGraph.size(). Each position i in the array aligns the hypothesis node with index i, so the array must cover every hypothesis node.
Solutions
- Recompute the index array against the exact hypGraph instance passed in
- Pass the graphs and indexes through the pipeline together so they cannot diverge
- Assert indexes.length == hypGraph.size() in caller code before the call
Example fix
// before
int[] indexes = computeIndexes(oldHypGraph);
SemGraph hypGraph = preprocess(oldHypGraph);
Alignment align = Alignment.makeFromIndexArray(txtGraph, hypGraph, indexes, j);
// after
int[] indexes = computeIndexes(hypGraph);
if (indexes.length != hypGraph.size()) { throw new IllegalStateException("stale alignment indexes"); }
Alignment align = Alignment.makeFromIndexArray(txtGraph, hypGraph, indexes, j); Defensive patterns
Strategy: validation
Validate before calling
if (indexes == null || hypGraph == null || indexes.length != hypGraph.size()) throw new IllegalArgumentException("indexes length must equal hypGraph.size()"); Type guard
boolean indexesMatchGraph(int[] indexes, SemGraph hypGraph) { return indexes != null && hypGraph != null && indexes.length == hypGraph.size(); } Try / catch
try { Alignment a = Alignment.makeFromIndexArray(txtGraph, hypGraph, indexes, j); } catch (IllegalArgumentException e) { throw new IllegalStateException("Stale alignment indexes: " + e.getMessage(), e); } Prevention
- Compute the index array from the same graph instance you pass to makeFromIndexArray
- Recompute indexes after any graph preprocessing (collapse, filter, re-index)
- Add an assertion on indexes.length == hypGraph.size() in pipeline code
When it happens
Trigger: Calling Alignment.makeFromIndexArray(txtGraph, hypGraph, indexes, ...) where indexes.length != hypGraph.size(), e.g. after the hypothesis graph was rebuilt or truncated after the array was computed.
Common situations: Graph preprocessed (nodes dropped, collapsed, or re-indexed) after alignment indexes were computed; array built from a different sentence or graph version; off-by-one when filtering empty nodes.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- Invalid txtGraph
- Invalid hypGraph
- shuffleWithSideInformation: sideInformation not of same…
- conditionalLogProbGivenPrevious requires given one less…
- conditionalLogProbsGivenPrevious requires given one less…
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/3a7d260f4c882056.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/semgraph/semgrex/Alignment.java:166
* {@code SemanticGraph} to the given text (passage) SemanticGraph, using
* the given array of indexes. The i'th node of the array should contain the
* index of the node in the text (passage) SemanticGraph to which the i'th
* node in the hypothesis SemanticGraph is aligned, or -1 if it is aligned to
* NO_WORD.
*/
public static Alignment makeFromIndexArray(SemanticGraph txtGraph,
SemanticGraph hypGraph,
int[] indexes,
double score,
String justification) {
if (txtGraph == null || txtGraph.isEmpty())
throw new IllegalArgumentException("Invalid txtGraph " + txtGraph);
if (hypGraph == null || hypGraph.isEmpty())
throw new IllegalArgumentException("Invalid hypGraph " + hypGraph);
if (indexes == null)
throw new IllegalArgumentException("Null index array");
if (indexes.length != hypGraph.size())
throw new IllegalArgumentException("Index array length " + indexes.length +
" does not match hypGraph size " + hypGraph.size());
Map<IndexedWord, IndexedWord> map =
Generics.newHashMap();
for (int i = 0; i < indexes.length; i++) {
IndexedWord hypNode = hypGraph.getNodeByIndex(i);
IndexedWord txtNode = IndexedWord.NO_WORD;
if (indexes[i] >= 0)
txtNode = txtGraph.getNodeByIndex(indexes[i]);
map.put(hypNode, txtNode);
}
return new Alignment(map, score, justification);
}
public static Alignment makeFromIndexArray(SemanticGraph txtGraph,
SemanticGraph hypGraph,
int[] indexes) {
return makeFromIndexArray(txtGraph, hypGraph, indexes, 0.0, null);
}View on GitHub (pinned to 1b7edd19c4)