{"record":{"id":"0e5baa9ce5ee3342","repo":"stanfordnlp/CoreNLP","slug":"invalid-txtgraph","errorCode":null,"errorMessage":"Invalid txtGraph ","messagePattern":"Invalid txtGraph ","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/semgraph/semgrex/Alignment.java","lineNumber":160,"sourceCode":"    return new Alignment(patchedMap, score, justification);\n  }\n\n\n  /**\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  }","sourceCodeStart":142,"sourceCodeEnd":178,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/semgraph/semgrex/Alignment.java#L142-L178","documentation":"Alignment.makeFromIndexArray throws IllegalArgumentException(\"Invalid txtGraph \" + txtGraph) when the source (text) SemanticGraph is null or empty. An alignment requires a non-empty text graph to map hyp words onto.","triggerScenarios":"Calling makeFromIndexArray with txtGraph == null, or with a SemanticGraph of size 0 (no vertices) — e.g. a graph built from an empty/degenerate parse.","commonSituations":"Pipelines that skip sentence construction for empty inputs and pass an unpopulated graph downstream; null graph propagation from a failed earlier parse step.","solutions":["Ensure the text graph was built successfully and sg.size() > 0 before creating an Alignment","Skip empty sentences upstream instead of passing empty graphs","Check for null return from the graph-building factory call"],"exampleFix":"// before\nAlignment a = Alignment.makeFromIndexArray(txtGraph, hypGraph, idx, 1.0, \"j\");\n// after\nif (txtGraph != null && txtGraph.size() > 0) {\n  Alignment a = Alignment.makeFromIndexArray(txtGraph, hypGraph, idx, 1.0, \"j\");\n}","handlingStrategy":"validation","validationCode":"if (txtGraph != null && txtGraph.size() > 0 && hypGraph != null && hypGraph.size() > 0) { Alignment a = Alignment.makeFromIndexArray(txtGraph, hypGraph, indexes, score, just); }","typeGuard":"boolean validGraph = g != null && !g.isEmpty() && g.size() > 0;","tryCatchPattern":"try { a = Alignment.makeFromIndexArray(txt, hyp, idx, score, just); } catch (IllegalArgumentException e) { log.warn(\"Alignment skipped: \" + e.getMessage()); }","preventionTips":["Skip empty/degenerate parses upstream instead of passing empty graphs","Null-check factory outputs before alignment","Add graph-population assertions after each parse step"],"tags":["java","nlp","semgrex","argument-validation"],"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"}