{"record":{"id":"0e7741b88f7ac40c","repo":"stanfordnlp/CoreNLP","slug":"invalid-annotation-to-tag-pattern-annopattern","errorCode":null,"errorMessage":"Invalid annotation to tag pattern: \" + annoPatternString","messagePattern":"Invalid annotation to tag pattern: \" \\+ annoPatternString","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/pipeline/CleanXmlAnnotator.java","lineNumber":330,"sourceCode":"  public void setTokenAnnotationPatterns(String conf) {\n    tokenAnnotationPatterns.clear();\n    // Patterns can only be tag attributes\n    addAnnotationPatterns(tokenAnnotationPatterns, conf, true);\n  }\n\n  public void setSectionAnnotationPatterns(String conf) {\n    sectionAnnotationPatterns.clear();\n    addAnnotationPatterns(sectionAnnotationPatterns, conf, false);\n  }\n\n  private static final Pattern TAG_ATTR_PATTERN = Pattern.compile(\"(.*)\\\\[(.*)\\\\]\");\n\n  private static void addAnnotationPatterns(CollectionValuedMap<Class, Pair<Pattern,Pattern>> annotationPatterns, String conf, boolean attrOnly) {\n    String[] annoPatternStrings = conf == null ? StringUtils.EMPTY_STRING_ARRAY : conf.trim().split(\"\\\\s*,\\\\s*\");\n    for (String annoPatternString:annoPatternStrings) {\n      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);","sourceCodeStart":312,"sourceCodeEnd":348,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/pipeline/CleanXmlAnnotator.java#L312-L348","documentation":"CleanXmlAnnotator's addAnnotationPatterns parses configuration strings of the form 'AnnotationKey=tagPattern' (comma separated). Each entry must contain a '='; if splitting on '=' yields fewer than two parts, it throws IllegalArgumentException('Invalid annotation to tag pattern: ...').","triggerScenarios":"Setting clean.xmlannotate.docs / .tokens / .sections style properties with a pattern string missing the 'key=value' separator, e.g. 'doc' instead of 'doc=doc'.","commonSituations":"Hand-edited CleanXML properties; examples copied incompletely; commas used inside a regex splitting the conf into malformed fragments.","solutions":["Write each pattern as 'AnnotationKey=regex', e.g. 'doc=<doc>' or 'sentence=<p>'","Check that regexes don't contain commas that split the conf incorrectly (escape or restructure)","Verify the annotation key part resolves to a known CoreAnnotations class (next error otherwise is 'Cannot resolve annotation key')"],"exampleFix":"// before\nprops.setProperty(\"clean.xmlannotate.docs\", \"doc\");\n// after\nprops.setProperty(\"clean.xmlannotate.docs\", \"doc=<doc>\");","handlingStrategy":"validation","validationCode":"for (String entry : conf.split(\"\\\\s*,\\\\s*\")) {\n  if (!entry.contains(\"=\")) throw new IllegalArgumentException(\"Invalid annotation to tag pattern: \" + entry);\n}","typeGuard":null,"tryCatchPattern":"try {\n  props.setProperty(\"clean.xmlannotate.docs\", conf);\n  new CleanXmlAnnotator(props);\n} catch (IllegalArgumentException e) {\n  if (e.getMessage().startsWith(\"Invalid annotation to tag pattern\")) {\n    // fix conf to 'key=pattern' form\n  } else throw e;\n}","preventionTips":["Always use 'AnnotationKey=regex' format for CleanXML pattern properties","Avoid commas inside regexes or split-proof them","Validate conf strings before setting properties"],"tags":["stanford-corenlp","cleanxml","invalid-format","configuration"],"backgroundTag":"invalid-argument-format","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"}