{"record":{"id":"4d6833ba77890a30","repo":"stanfordnlp/CoreNLP","slug":"cannot-determine-annotation-key-for-propname","errorCode":null,"errorMessage":"Cannot determine annotation key for ${propName}=${matchedExpressionsAnnotationKeyName}","messagePattern":"Cannot determine annotation key for (.+?)=(.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/pipeline/TokensRegexAnnotator.java","lineNumber":90,"sourceCode":"      System.err.println(\"using case insensitive!\");\n      env.setDefaultStringMatchFlags(NodePattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE);\n      env.setDefaultStringPatternFlags(Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE);\n    }\n    if (files.length != 0) {\n      extractor = CoreMapExpressionExtractor.createExtractorFromFiles(env, files);\n    } else {\n      extractor = null;\n    }\n    verbose = PropertiesUtils.getBool(props, prefix + \"verbose\", false);\n    options.setTokenOffsets = PropertiesUtils.getBool(props, prefix + \"setTokenOffsets\", options.setTokenOffsets);\n    options.extractWithTokens = PropertiesUtils.getBool(props, prefix + \"extractWithTokens\", options.extractWithTokens);\n    options.flatten = PropertiesUtils.getBool(props, prefix + \"flatten\", options.flatten);\n    String matchedExpressionsAnnotationKeyName = props.getProperty(prefix + \"matchedExpressionsAnnotationKey\");\n    if (matchedExpressionsAnnotationKeyName != null) {\n      options.matchedExpressionsAnnotationKey = EnvLookup.lookupAnnotationKeyWithClassname(env, matchedExpressionsAnnotationKeyName);\n      if (options.matchedExpressionsAnnotationKey == null) {\n        String propName = prefix + \"matchedExpressionsAnnotationKey\";\n        throw new RuntimeException(\"Cannot determine annotation key for \" + propName + '=' + matchedExpressionsAnnotationKeyName);\n      }\n    }\n  }\n\n  public TokensRegexAnnotator(Properties props) {\n    this(null, props);\n  }\n\n\n  private static void addTokenOffsets(CoreMap annotation) {\n    // We are going to mark the token begin and token end for each token\n    Integer startTokenOffset = annotation.get(CoreAnnotations.TokenBeginAnnotation.class);\n    if (startTokenOffset == null) {\n      startTokenOffset = 0;\n    }\n    //set token offsets\n    int i = 0;\n    for (CoreMap c:annotation.get(CoreAnnotations.TokensAnnotation.class)) {","sourceCodeStart":72,"sourceCodeEnd":108,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/pipeline/TokensRegexAnnotator.java#L72-L108","documentation":"TokensRegexAnnotator reads the 'tokensregex.matchedExpressionsAnnotationKey' option and resolves it via EnvLookup.lookupAnnotationKeyWithClassname against the environment. If the name cannot be resolved to a Class<? extends CoreAnnotation> key, it throws RuntimeException stating the property and its value.","triggerScenarios":"Setting the matchedExpressionsAnnotationKey option to a string that is not a registered annotation key class name in the TokensRegex environment (misspelled class name, custom annotation not registered in the env, or a plain word).","commonSituations":"Typos in class names like CoreAnnotations.TextAnnotation; using a custom annotation class without declaring it to the environment; copying an option name from docs of a different CoreNLP version.","solutions":["Use a fully-qualified name of an existing CoreAnnotations key, e.g. edu.stanford.nlp.ling.CoreAnnotations$TextAnnotation.","Register your custom annotation key in the TokensRegex env before referencing it.","Verify resolution by calling EnvLookup.lookupAnnotationKeyWithClassname yourself in a test.","Remove the option to use default behavior if you do not need matched expressions stored."],"exampleFix":"// before\nprops.setProperty(\"tokensregex.matchedExpressionsAnnotationKey\", \"MyMatchKey\");\n// after\nprops.setProperty(\"tokensregex.matchedExpressionsAnnotationKey\", \"edu.stanford.nlp.ling.CoreAnnotations$TextAnnotation\");","handlingStrategy":"validation","validationCode":"String keyName = props.getProperty(\"tokensregex.matchedExpressionsAnnotationKey\");\nif (keyName != null && EnvLookup.lookupAnnotationKeyWithClassname(env, keyName) == null)\n  throw new IllegalStateException(\"matchedExpressionsAnnotationKey not resolvable: \" + keyName);","typeGuard":"boolean isResolvableAnnotationKey(Env env, String name) { return EnvLookup.lookupAnnotationKeyWithClassname(env, name) != null; }","tryCatchPattern":"try { new TokensRegexAnnotator(props); } catch (RuntimeException e) { if (e.getMessage().startsWith(\"Cannot determine annotation key\")) { log.error(\"Check matchedExpressionsAnnotationKey: \" + e.getMessage()); } throw e; }","preventionTips":["Use fully-qualified CoreAnnotations$X names in config","Register custom annotation classes in the env before use","Validate annotation-key options in a config test"],"tags":["java","tokensregex","configuration","annotation-key","corenlp"],"backgroundTag":"invalid-config-value","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"}