{"record":{"id":"76aa56f3cb6e449c","repo":"stanfordnlp/CoreNLP","slug":"splitword-expected-a-headindex-0-indexed-for-the","errorCode":null,"errorMessage":"SplitWord expected a -headIndex, 0-indexed for the word piece to use when chopping up the word","messagePattern":"SplitWord expected a -headIndex, 0-indexed for the word piece to use when chopping up the word","errorType":"exception","errorClass":"SsurgeonParseException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/semgraph/semgrex/ssurgeon/SplitWord.java","lineNumber":72,"sourceCode":"    if (nodePieces == null || nodePieces.size() == 0) {\n      throw new SsurgeonParseException(\"SplitWord expected -exact or -regex with regex to determine which pieces to split the word into\");\n    }\n    if (nodePieces.size() == 1) {\n      throw new SsurgeonParseException(\"SplitWord expected at least two -exact or -regex\");\n    }\n    if (exactSplit) {\n      this.exactPieces = new ArrayList<>(nodePieces);\n      this.nodeRegex = null;\n    } else {\n      this.nodeRegex = new ArrayList<>();\n      for (int i = 0; i < nodePieces.size(); ++i) {\n        this.nodeRegex.add(Pattern.compile(nodePieces.get(i)));\n      }\n      this.exactPieces = null;\n    }\n\n    if (headIndex == null) {\n      throw new SsurgeonParseException(\"SplitWord expected a -headIndex, 0-indexed for the word piece to use when chopping up the word\");\n    }\n    this.headIndex = headIndex;\n\n    if (relation == null) {\n      throw new SsurgeonParseException(\"SplitWord expected a -reln to represent the dependency to use for the new words\");\n    }\n    this.relation = relation;\n\n    if (nodeNames != null) {\n      String[] namePieces = nodeNames.split(\",\");\n      this.nodeNames = new HashMap<>();\n      for (String namePiece : namePieces) {\n        String[] pieces = namePiece.split(\"=\", 2);\n        if (pieces.length < 2) {\n          throw new SsurgeonParseException(\"SplitWord got a -name parameter which did not have a number for one of the names.  Should look like 0=foo,1=bar\");\n        }\n        int idx = Integer.valueOf(pieces[0]);\n        if (idx >= nodePieces.size()) {","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/semgraph/semgrex/ssurgeon/SplitWord.java#L54-L90","documentation":"SplitWord must know which piece becomes the head of the re-attached dependency subtree; this is given by the 0-indexed -headIndex argument. If headIndex is null, the constructor throws SsurgeonParseException.","triggerScenarios":"Constructing SplitWord without the -headIndex flag (or passing null Integer as the third constructor argument).","commonSituations":"Writing an ssurgeon rule and omitting -headIndex because it seems optional; a null Integer auto-boxed from an unparsed command-line value; copying an older SplitWord invocation predating the headIndex argument.","solutions":["Add -headIndex N (0-indexed) pointing at the piece that should inherit the original head relation, e.g. -headIndex 0","Pass a non-null Integer as the headIndex constructor parameter","Double-check that N is within range: 0 <= N < nodePieces.size() to avoid later index errors"],"exampleFix":"// before\nnew SplitWord(\"w\", pieces, null, reln, null, true);\n// after\nnew SplitWord(\"w\", pieces, 0, reln, null, true); // first piece is the head","handlingStrategy":"validation","validationCode":"if (headIndex == null || headIndex < 0 || headIndex >= nodePieces.size()) throw new IllegalArgumentException(\"-headIndex must be a 0-based index into the pieces\");","typeGuard":null,"tryCatchPattern":"try { SplitWord sw = new SplitWord(node, pieces, headIndex, reln, names, exact); } catch (SsurgeonParseException e) { log.error(\"Missing -headIndex: \" + e.getMessage()); }","preventionTips":["Always include -headIndex when writing SplitWord rules","Range-check headIndex against the piece count","Keep a template ssurgeon rule containing all required SplitWord flags"],"tags":["ssurgeon","constructor","missing-argument"],"backgroundTag":"missing-required-argument","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}