{"record":{"id":"8090f50b6c43ceb0","repo":"stanfordnlp/CoreNLP","slug":"invalid-tag-pattern-pattern-for-annotatio","errorCode":null,"errorMessage":"Invalid tag pattern: \" + pattern + \" for annotation key \" + annoKeyString","messagePattern":"Invalid tag pattern: \" \\+ pattern \\+ \" for annotation key \" \\+ annoKeyString","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/pipeline/CleanXmlAnnotator.java","lineNumber":346,"sourceCode":"      String[] annoPattern = annoPatternString.split(\"\\\\s*=\\\\s*\", 2);\n      if (annoPattern.length != 2) {\n        throw new IllegalArgumentException(\"Invalid annotation to tag pattern: \" + annoPatternString);\n      }\n      String annoKeyString = annoPattern[0];\n      String pattern = annoPattern[1];\n      Class annoKey = EnvLookup.lookupAnnotationKeyWithClassname(null, annoKeyString);\n      if (annoKey == null) {\n        throw new IllegalArgumentException(\"Cannot resolve annotation key \" + annoKeyString);\n      }\n      Matcher m = TAG_ATTR_PATTERN.matcher(pattern);\n      if (m.matches()) {\n        Pattern tagPattern = toCaseInsensitivePattern(m.group(1));\n        Pattern attrPattern = toCaseInsensitivePattern(m.group(2));\n        annotationPatterns.add(annoKey, Pair.makePair(tagPattern, attrPattern));\n      } else {\n        if (attrOnly) {\n          // attribute is require\n          throw new IllegalArgumentException(\"Invalid tag pattern: \" + pattern + \" for annotation key \" + annoKeyString);\n        } else {\n          Pattern tagPattern = toCaseInsensitivePattern(pattern);\n          annotationPatterns.add(annoKey, Pair.makePair(tagPattern, null));\n        }\n      }\n    }\n  }\n\n  /**\n   * Helper method to set the TokenBeginAnnotation and TokenEndAnnotation of every token.\n   */\n  public void setTokenBeginTokenEnd(List<CoreLabel> tokensList) {\n    int tokenIndex = 0;\n    for (CoreLabel token : tokensList) {\n      token.set(CoreAnnotations.TokenBeginAnnotation.class, tokenIndex);\n      token.set(CoreAnnotations.TokenEndAnnotation.class, tokenIndex+1);\n      tokenIndex++;\n    }","sourceCodeStart":328,"sourceCodeEnd":364,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/pipeline/CleanXmlAnnotator.java#L328-L364","documentation":"After resolving the annotation key, the pattern part of the config must match TAG_ATTR_PATTERN (tag or tag/attribute). When it does not match and attrOnly is set (attribute required), addAnnotationPatterns throws IllegalArgumentException because it cannot build a tag/attribute matcher.","triggerScenarios":"Calling setDocAnnotationPatterns/setTokenAnnotationPatterns/setSectionAnnotationPatterns with a pattern string whose tag portion fails TAG_ATTR_PATTERN when an attribute is required (attrOnly mode), e.g. a malformed \"word,/type=x\" style pattern or empty/invalid tag regex.","commonSituations":"Misplaced separators in the comma-separated config; attribute-only patterns supplied where the tag part is empty; regexes containing characters that break the expected tag[/attr] structure.","solutions":["Rewrite the pattern to the expected form \"annotationKey,tagRegex[/attrRegex]\" so it matches TAG_ATTR_PATTERN.","If you only need attribute matching, supply a valid attribute specification with a non-empty tag part.","Escape regex metacharacters so the tag portion parses as a single tag pattern."],"exampleFix":"// before\nprops.setProperty(\"clean.xmltokenannotationpatterns\", \"word,/speaker=*\");\n// after\nprops.setProperty(\"clean.xmltokenannotationpatterns\", \"word, speaker|.*\");","handlingStrategy":"validation","validationCode":"String[] parts = patternSpec.split(\",\", 2);\nif (parts.length < 2 || !parts[1].matches(\"[^/]+(/[^/]*)?\")) throw new IllegalArgumentException(\"Bad CleanXml pattern: \" + patternSpec);","typeGuard":null,"tryCatchPattern":"try { annotator.setTokenAnnotationPatterns(specs); } catch (IllegalArgumentException e) { if (e.getMessage().startsWith(\"Invalid tag pattern\")) { log.error(\"Malformed tag pattern: \" + e.getMessage()); } else { throw e; } }","preventionTips":["Follow the documented format annotationKey,tagRegex[/attrRegex] exactly.","Escape regex metacharacters in tag names before embedding them in patterns.","Test each pattern against sample XML in a unit test."],"tags":["stanford-corenlp","cleanxml","regex","invalid-argument-format"],"backgroundTag":"invalid-regex-pattern","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"}