{"record":{"id":"6289811cab76560f","repo":"stanfordnlp/CoreNLP","slug":"variable","errorCode":null,"errorMessage":"Variable ","messagePattern":"Variable ","errorType":"exception","errorClass":"ParseException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/trees/tregex/TregexParser.jj","lineNumber":164,"sourceCode":"\nDescriptionPattern Description(Relation r, boolean negateDesc, boolean cat) : {\n  Token desc = null;\n  Token name = null;\n  Token linkedName = null;\n  boolean link = false;\n  Token groupNum;\n  Token groupVar;\n  List<Pair<Integer,String>> varGroups = new ArrayList<Pair<Integer,String>>();\n} {\n// this is how we match tokens\n// the return value of tokens is a Token object\n  ( ( ( desc = <IDENTIFIER> | desc = <REGEX> | desc = <BLANK> | desc = <ROOTNODE> )\n    ( ( \"#\" groupNum = <NUMBER> \"%\" groupVar = <IDENTIFIER> ) {\n        varGroups.add(new Pair<Integer,String>(Integer.parseInt(groupNum.image),groupVar.image));\n      } )*\n      ( ( \"=\" name = <IDENTIFIER> )\n        { if (knownVariables.contains(name.image)) {\n            throw new ParseException(\"Variable \" + name.image + \" has been declared twice, which makes no sense\");\n          } else {\n            knownVariables.add(name.image);\n          }\n          if (underNegation)\n            throw new ParseException(\"No named tregex nodes allowed in the scope of negation.\");\n        } )? ) |\n    ( ( \"~\" linkedName = <IDENTIFIER> ) ( \"=\" name = <IDENTIFIER> )? {\n        if (!knownVariables.contains(linkedName.image)) {\n          throw new ParseException(\"Variable \" + linkedName.image +\n                                   \" was referenced before it was declared\");\n        }\n        if (name != null) {\n          if (knownVariables.contains(name.image)) {\n            throw new ParseException(\"Variable \" + name.image + \" has been declared twice, which makes no sense\");\n          } else {\n            knownVariables.add(name.image);\n          }\n        }","sourceCodeStart":146,"sourceCodeEnd":182,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/trees/tregex/TregexParser.jj#L146-L182","documentation":"TregexParseException thrown while parsing a tregex node description. When a node description carries a \"=name\" assignment, the parser checks its table of already-declared variables and rejects a name that has been assigned to two different nodes in the same pattern, since back-references by name would be ambiguous. The message is a bare prefix \"Variable \" because the exception text continues with the variable name and the fixed suffix \"has been declared twice, which makes no sense\".","triggerScenarios":"Parsing a tregex pattern where two node descriptions in the same relation tree are both named with the same \"=name\" label, e.g. \"A=B < C=B\"; the second declaration of B hits knownVariables.contains(name.image) at TregexParser.jj:164.","commonSituations":"Copy-pasting or editing a long tregex pattern and reusing a node label; programmatically generating patterns where a template variable collides with a hand-written label.","solutions":["Rename one of the two \"=label\" assignments so every node name in the pattern is unique.","Remove the redundant \"=name\" from the second node if you do not need to capture it.","If the pattern is generated, add a check that emitted labels are unique before compiling the pattern."],"exampleFix":"// before\nTregexPattern p = TregexPattern.compile(\"NP < (NN=name) < (NN=name)\");\n// after\nTregexPattern p = TregexPattern.compile(\"NP < (NN=name1) < (NN=name2)\");","handlingStrategy":"validation","validationCode":"boolean hasUniqueNames(String pattern) {\n  java.util.regex.Matcher m = java.util.regex.Pattern.compile(\"=([A-Za-z_][A-Za-z0-9_]*)\").matcher(pattern);\n  java.util.Set<String> seen = new java.util.HashSet<>();\n  while (m.find()) { if (!seen.add(m.group(1))) return false; }\n  return true;\n}","typeGuard":null,"tryCatchPattern":"try { TregexPattern p = TregexPattern.compile(pattern); } catch (TregexParseException e) { reportDuplicateNames(pattern, e); }","preventionTips":["Keep node label conventions unique per pattern (e.g. prefix by clause)","Validate patterns with a unit test corpus before deploying","When generating patterns programmatically, assert label uniqueness"],"tags":["parser","tregex","duplicate-identifier"],"backgroundTag":"invalid-identifier-format","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"}