{"record":{"id":"371f6155a807605a","repo":"stanfordnlp/CoreNLP","slug":"null-index-array","errorCode":null,"errorMessage":"Null index array","messagePattern":"Null index array","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/semgraph/semgrex/Alignment.java","lineNumber":164,"sourceCode":"  /**\n   * Constructs and returns a new Alignment from the given hypothesis\n   * {@code SemanticGraph} to the given text (passage) SemanticGraph, using\n   * the given array of indexes.  The i'th node of the array should contain the\n   * index of the node in the text (passage) SemanticGraph to which the i'th\n   * node in the hypothesis SemanticGraph is aligned, or -1 if it is aligned to\n   * NO_WORD.\n   */\n  public static Alignment makeFromIndexArray(SemanticGraph txtGraph,\n                                             SemanticGraph hypGraph,\n                                             int[] indexes,\n                                             double score,\n                                             String justification) {\n    if (txtGraph == null || txtGraph.isEmpty())\n      throw new IllegalArgumentException(\"Invalid txtGraph \" + txtGraph);\n    if (hypGraph == null || hypGraph.isEmpty())\n      throw new IllegalArgumentException(\"Invalid hypGraph \" + hypGraph);\n    if (indexes == null)\n      throw new IllegalArgumentException(\"Null index array\");\n    if (indexes.length != hypGraph.size())\n      throw new IllegalArgumentException(\"Index array length \" + indexes.length +\n                                         \" does not match hypGraph size \" + hypGraph.size());\n    Map<IndexedWord, IndexedWord> map =\n      Generics.newHashMap();\n    for (int i = 0; i < indexes.length; i++) {\n      IndexedWord hypNode = hypGraph.getNodeByIndex(i);\n      IndexedWord txtNode = IndexedWord.NO_WORD;\n      if (indexes[i] >= 0)\n        txtNode = txtGraph.getNodeByIndex(indexes[i]);\n      map.put(hypNode, txtNode);\n    }\n    return new Alignment(map, score, justification);\n  }\n\n  public static Alignment makeFromIndexArray(SemanticGraph txtGraph,\n                                             SemanticGraph hypGraph,\n                                             int[] indexes) {","sourceCodeStart":146,"sourceCodeEnd":182,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/semgraph/semgrex/Alignment.java#L146-L182","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nAlignment align = Alignment.makeFromIndexArray(txtGraph, hypGraph, null, justification);\n// after\nif (indexes == null) { throw new IllegalStateException(\"No alignment indexes computed\"); }\nAlignment align = Alignment.makeFromIndexArray(txtGraph, hypGraph, indexes, justification);","handlingStrategy":"validation","validationCode":"if (indexes == null) throw new IllegalArgumentException(\"indexes must be non-null\");\nif (hypGraph != null && indexes.length != hypGraph.size()) throw new IllegalArgumentException(\"indexes length mismatch\");","typeGuard":"boolean isValidIndexes(int[] indexes, SemGraph hypGraph) { return indexes != null && hypGraph != null && indexes.length == hypGraph.size(); }","tryCatchPattern":"try { Alignment a = Alignment.makeFromIndexArray(txtGraph, hypGraph, indexes, j); } catch (IllegalArgumentException e) { log.error(\"Bad alignment input: \" + e.getMessage()); }","preventionTips":["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"],"tags":["java","null-argument","semgrex"],"backgroundTag":"null-argument","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"}