stanfordnlp/CoreNLP · error · IllegalArgumentException
Null index array
Error message
Null index array
What it means
Alignment.makeFromIndexArray throws IllegalArgumentException when the supplied int[] of node indexes is null. The method aligns nodes of a hypothesis Semgraph to a text Semgraph and requires an index array exactly matching the hypothesis graph's size, so a null array cannot be processed.
Solutions
- Ensure the int[] passed as indexes is allocated and populated before calling makeFromIndexArray
- Add a null check on the caller side and return an empty Alignment or throw a descriptive error upstream
- Verify the upstream method producing the index array never returns null on failure paths
Example fix
// before
Alignment align = Alignment.makeFromIndexArray(txtGraph, hypGraph, null, justification);
// after
if (indexes == null) { throw new IllegalStateException("No alignment indexes computed"); }
Alignment align = Alignment.makeFromIndexArray(txtGraph, hypGraph, indexes, justification); Defensive patterns
Strategy: validation
Validate before calling
if (indexes == null) throw new IllegalArgumentException("indexes must be non-null");
if (hypGraph != null && indexes.length != hypGraph.size()) throw new IllegalArgumentException("indexes length mismatch"); Type guard
boolean isValidIndexes(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) { log.error("Bad alignment input: " + e.getMessage()); } Prevention
- Never pass a possibly-null array straight into factory methods
- Initialize index arrays at declaration or make upstream methods return empty arrays instead of null
- Validate array length against graph size before invoking alignment
When it happens
Trigger: Calling Alignment.makeFromIndexArray(txtGraph, hypGraph, null, ...) with a null int[] indexes argument, typically when the alignment array comes from an upstream computation that returned null.
Common situations: Pipeline code where alignment indexes are produced by another method (e.g. a matcher or aligner) that can return null on no match; uninitialized array fields passed straight into the factory method.
Related errors
- Must supply a target label to compute precision and recall…
- Annotation field cannot be null
- Cannot match against null elements
- Invalid txtGraph
- Invalid hypGraph
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/371f6155a807605a.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/semgraph/semgrex/Alignment.java:164
/**
* Constructs and returns a new Alignment from the given hypothesis
* {@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) {View on GitHub (pinned to 1b7edd19c4)