{"record":{"id":"9a3880054249c635","repo":"stanfordnlp/CoreNLP","slug":"splitword-got-an-index-in-name-which-was-larger-t","errorCode":null,"errorMessage":"SplitWord got an index in -name which was larger than the largest possible split piece, ${idx} (this is 0-indexed)","messagePattern":"SplitWord got an index in -name which was larger than the largest possible split piece, (.+?) \\(this is 0-indexed\\)","errorType":"exception","errorClass":"SsurgeonParseException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/semgraph/semgrex/ssurgeon/SplitWord.java","lineNumber":91,"sourceCode":"    }\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()) {\n          throw new SsurgeonParseException(\"SplitWord got an index in -name which was larger than the largest possible split piece, \" + idx + \" (this is 0-indexed)\");\n        }\n        this.nodeNames.put(idx, pieces[1]);\n      }\n    } else {\n      this.nodeNames = Collections.emptyMap();\n    }\n  }\n\n  @Override\n  public String toEditString() {\n    StringWriter buf = new StringWriter();\n    buf.write(LABEL);\n    buf.write(\"\\t\");\n    buf.write(\"-node \" + node + \"\\t\");\n    if (nodeRegex != null) {\n      for (Pattern regex : nodeRegex) {\n        buf.write(\"-regex \" + regex + \"\\t\");\n      }","sourceCodeStart":73,"sourceCodeEnd":109,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/semgraph/semgrex/ssurgeon/SplitWord.java#L73-L109","documentation":"SplitWord parses a -name argument of the form 'idx=name' mapping split-piece indices to new node names. SsurgeonParseException is thrown when the index given is >= the number of split pieces the word was actually split into. Indices are 0-indexed, so the largest legal index is pieces.size()-1.","triggerScenarios":"Calling SplitWord (via an ssurgeon edit line like 'splitword -node ... -name 3=foo') where the node's word splits into fewer pieces than the index used, e.g. -name 2=x on a word that splits into only 2 pieces (indices 0 and 1). Also triggered by typo'd indices or assuming 1-based indexing.","commonSituations":"Hand-written Ssurgeon rule files where the -name index assumes a different split result than the regex produces; off-by-one mistakes because the message says '0-indexed'; rule templates reused against words with fewer delimiters.","solutions":["Lower the -name index to be within 0..(number of split pieces - 1).","Check the split regex/pattern on the -node word to confirm how many pieces it actually produces for your input.","If using 1-based numbering in your head, subtract 1 from every -name index.","Wrap rule loading in a try-catch for SsurgeonParseException and report the offending edit line."],"exampleFix":"// before\nsplitword -node node -pattern \"-\" -name 2=part\n// after (word has only 2 pieces: 0 and 1)\nsplitword -node node -pattern \"-\" -name 1=part","handlingStrategy":"validation","validationCode":"String[] pieces = word.split(pattern);\nfor (String nameSpec : nameSpecs) {\n  int idx = Integer.parseInt(nameSpec.split(\"=\", 2)[0]);\n  if (idx < 0 || idx >= pieces.length)\n    throw new IllegalArgumentException(\"-name index \" + idx + \" out of range for \" + pieces.length + \" pieces\");\n}","typeGuard":null,"tryCatchPattern":"try { Ssurgeon.add_compound_rules(ruleFile); } catch (SsurgeonParseException e) { log.error(\"Bad splitword -name in rule: \" + e.getMessage()); }","preventionTips":["Verify the split pattern produces the expected piece count on sample words","Remember -name indices are 0-indexed","Test ssurgeon rules on a small corpus before production use"],"tags":["parsing","ssurgeon","index-out-of-range"],"backgroundTag":"index-out-of-range","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"}