{"record":{"id":"f69fb65db79c439d","repo":"stanfordnlp/CoreNLP","slug":"cannot-resolve-annotation-key-annokeystring","errorCode":null,"errorMessage":"Cannot resolve annotation key \" + annoKeyString","messagePattern":"Cannot resolve annotation key \" \\+ annoKeyString","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/pipeline/CleanXmlAnnotator.java","lineNumber":336,"sourceCode":"  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);\n          annotationPatterns.add(annoKey, Pair.makePair(tagPattern, null));\n        }\n      }\n    }\n  }\n","sourceCodeStart":318,"sourceCodeEnd":354,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/pipeline/CleanXmlAnnotator.java#L318-L354","documentation":"CleanXmlAnnotator accepts string configs (xmlTags, sentenceEndingTags, etc.) where each pattern's first part must name a CoreMap annotation key (e.g. \"word\", \"lemma\"). addAnnotationPatterns resolves that name via EnvLookup.lookupAnnotationKeyWithClassname; if the name is not a known annotation class/field it cannot map the config to an annotation Class and throws IllegalArgumentException.","triggerScenarios":"Calling setDocAnnotationPatterns / setTokenAnnotationPatterns / setSectionAnnotationPatterns (or setting properties like clean.xmltokenannotationpatterns) with a pattern string whose annotation part is misspelled or not a valid CoreAnnotation class name, e.g. \"tok,.*\" instead of \"word,.*\".","commonSituations":"Typo in the annotation key portion of a comma-separated pattern; using a custom annotation whose class is not on the classpath or not registered; copying patterns from docs that use different key names across Stanford CoreNLP versions.","solutions":["Fix the annotation key string to a valid CoreAnnotations key (e.g. word, tag, lemma, ner).","Verify the class name spelling and that any custom annotation class is fully qualified and on the classpath.","Check the expected pattern format: \"annotationKey,tagPattern[/attrPattern]\" as split on comma."],"exampleFix":"// before\nannotatorProps.setProperty(\"clean.xmltokenannotationpatterns\", \"tok,.*\");\n// after\nannotatorProps.setProperty(\"clean.xmltokenannotationpatterns\", \"word,.*\");","handlingStrategy":"validation","validationCode":"Class<?> key = EnvLookup.lookupAnnotationKeyWithClassname(null, annoKeyString);\nif (key == null) throw new IllegalArgumentException(\"Unknown annotation key: \" + annoKeyString);","typeGuard":null,"tryCatchPattern":"try { annotator.setDocAnnotationPatterns(patterns); } catch (IllegalArgumentException e) { if (e.getMessage().startsWith(\"Cannot resolve annotation key\")) { log.error(\"Fix the annotation key in CleanXml patterns: \" + e.getMessage()); } else { throw e; } }","preventionTips":["Only use well-known CoreAnnotations key names (word, tag, lemma, ner) in CleanXml patterns.","Fully qualify custom annotation classes and keep them on the classpath.","Keep pattern strings in a constants file and unit-test pattern setup at startup."],"tags":["stanford-corenlp","cleanxml","annotation-key","config"],"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-16T04:17:20.429Z"}