{"record":{"id":"01e78a7b626b2f0c","repo":"stanfordnlp/CoreNLP","slug":"node-name-name-does-not-exist-in-the-searc","errorCode":null,"errorMessage":"Node name \" + name + \" does not exist in the searched tree","messagePattern":"Node name \" \\+ name \\+ \" does not exist in the searched tree","errorType":"exception","errorClass":"NullPointerException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/trees/tregex/tsurgeon/RelabelNode.java","lineNumber":161,"sourceCode":"    public Tree evaluate(Tree tree, TregexMatcher tregex) {\n      Tree nodeToRelabel = childMatcher[0].evaluate(tree, tregex);\n      switch (mode) {\n      case FIXED: {\n        nodeToRelabel.label().setValue(newLabel);\n        break;\n      }\n      case REGEX: {\n        Matcher m = labelRegex.matcher(nodeToRelabel.label().value());\n        StringBuilder label = new StringBuilder();\n        for (String chunk : replacementPieces) {\n          if (variablePattern.matcher(chunk).matches()) {\n            String name = chunk.substring(2, chunk.length() - 1);\n            label.append(Matcher.quoteReplacement(tregex.getVariableString(name)));\n          } else if (nodePattern.matcher(chunk).matches()) {\n            String name = chunk.substring(2, chunk.length() - 1);\n            Tree node = tregex.getNode(name);\n            if (node == null) {\n              throw new NullPointerException(\"Node name \" + name + \" does not exist in the searched tree\");\n            }\n            label.append(Matcher.quoteReplacement(node.value()));\n          } else {\n            label.append(chunk);\n          }\n        }\n        nodeToRelabel.label().setValue(m.replaceAll(label.toString()));\n        break;\n      }\n      default:\n        throw new AssertionError(\"Unsupported relabel mode \" + mode);\n      }\n      return tree;\n    }\n  }\n\n  @Override\n  public String toString() {","sourceCodeStart":143,"sourceCodeEnd":179,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/trees/tregex/tsurgeon/RelabelNode.java#L143-L179","documentation":"RelabelNode.evaluate supports relabel patterns like '/regex/{...=name...}' that reference captured nodes by name. When the relabel template references a name that the tregex match did not bind to any node, tregex.getNode returns null and a NullPointerException is thrown to signal the missing named node.","triggerScenarios":"A relabel operation with a '{=name}' or '/{name}/' reference where `name` never appears as a captured node name (no '=name' in the tregex pattern), so tregex.getVariableString/getNode finds nothing.","commonSituations":"Mismatch between the names used in the relabel template and those captured in the tregex expression (typo, renamed variable, pattern changed but relabel not updated); running Tsurgeon scripts where tregex and relabel were edited independently.","solutions":["Ensure every name referenced in the relabel pattern appears as a named capture ('=name') in the accompanying tregex pattern.","Check spelling — names are matched exactly.","Wrap Tsurgeon processing in try/catch (RuntimeException) to report the bad script entry instead of aborting the whole batch."],"exampleFix":"// before\ntregex: \"@NP\" relabel: \"/^NP$/{=head}\" // '=head' never captured\n// after\ntregex: \"@NP <1=head\" relabel: \"/^NP$/{=head}\"","handlingStrategy":"validation","validationCode":"static boolean relabelNamesCaptured(String tregex, String relabelTemplate) {\n  java.util.regex.Matcher m = java.util.regex.Pattern.compile(\"\\\\{=([A-Za-z0-9_]+)\\\\}\").matcher(relabelTemplate);\n  while (m.find()) {\n    if (!tregex.contains(\"=\" + m.group(1))) return false;\n  }\n  return true;\n}","typeGuard":null,"tryCatchPattern":"try {\n  tree = op.evaluate(tree, matcher);\n} catch (NullPointerException e) {\n  if (e.getMessage() != null && e.getMessage().startsWith(\"Node name \")) {\n    log.warn(\"Relabel references unknown node: \" + e.getMessage());\n  } else throw e;\n}","preventionTips":["Verify every '{=name}' in relabel templates has a matching '=name' capture in the tregex pattern.","Keep tregex and relabel definitions together in the script so renames stay in sync.","Validate Tsurgeon scripts at load time against the pattern's captured names (parser.knownVariables)."],"tags":["tsurgeon","null-reference","tree-manipulation"],"backgroundTag":"entity-not-found","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"}