{"record":{"id":"00a2b7244863309f","repo":"stanfordnlp/CoreNLP","slug":"unable-to-annotate-attribute-key","errorCode":null,"errorMessage":"Unable to annotate attribute \" + key","messagePattern":"Unable to annotate attribute \" \\+ key","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/pipeline/ChunkAnnotationUtils.java","lineNumber":860,"sourceCode":"  public static void annotateChunk(CoreMap chunk, Map<String,String> attributes) {\n    for (Map.Entry<String, String> entry : attributes.entrySet()) {\n      String key = entry.getKey();\n      String value = entry.getValue();\n      Class coreKeyClass = AnnotationLookup.toCoreKey(key);\n      if (key != null) {\n        if (value != null)  {\n          try {\n            Class valueClass = AnnotationLookup.getValueType(coreKeyClass);\n            if (valueClass == String.class) {\n              chunk.set(coreKeyClass, value);\n            } else {\n             Method valueOfMethod = valueClass.getMethod(\"valueOf\", String.class);\n              if (valueOfMethod != null) {\n                chunk.set(coreKeyClass, valueOfMethod.invoke(valueClass, value));\n              }\n            }\n          } catch (Exception ex) {\n            throw new RuntimeException(\"Unable to annotate attribute \" + key, ex);\n          }\n        } else {\n          chunk.set(coreKeyClass, null);\n        }\n      } else {\n        throw new UnsupportedOperationException(\"Unknown null attribute.\");\n      }\n    }\n  }\n\n  public static void annotateChunks(List<? extends CoreMap> chunks, int start, int end, Map<String,String> attributes) {\n    for (int i = start; i < end; i++) {\n      annotateChunk(chunks.get(i), attributes);\n    }\n  }\n\n  public static void annotateChunks(List<? extends CoreMap> chunks, Map<String,String> attributes) {\n    for (CoreMap chunk:chunks) {","sourceCodeStart":842,"sourceCodeEnd":878,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/pipeline/ChunkAnnotationUtils.java#L842-L878","documentation":"ChunkAnnotationUtils.annotateWithMatchingFields maps attribute name/value strings onto CoreMap annotation keys via reflection (key class lookup plus a valueOf(String) method). Any failure in that reflective pipeline is rethrown as RuntimeException('Unable to annotate attribute ' + key, ex), preserving the cause.","triggerScenarios":"Calling annotateChunk/annotateChunks with an attributes map whose key does not resolve to a valid annotation key class, or whose value cannot be parsed by that key class's valueOf(String) method (e.g. 'MyCoreMap=not-a-number' for an integer key).","commonSituations":"Typo'd annotation key names in config; value strings of the wrong format for the target type; annotation class not on the classpath; passing custom keys unsupported by EnvLookup.","solutions":["Inspect the wrapped cause (ex) to see whether key lookup or valueOf parsing failed","Correct the attribute key to a valid CoreAnnotations class name","Ensure the value string parses for the key's type (e.g. valid integer for an Integer key)","Verify the annotation classes are on the classpath"],"exampleFix":"// before\nattributes.put(\"Position\", \"abc\"); // Position is Integer\n// after\nattributes.put(\"Position\", \"5\");","handlingStrategy":"validation","validationCode":"for (Map.Entry<String,String> e : attributes.entrySet()) {\n  if (EnvLookup.lookupAnnotationKeyWithClassname(null, e.getKey()) == null)\n    throw new IllegalArgumentException(\"Unknown annotation key: \" + e.getKey());\n}","typeGuard":null,"tryCatchPattern":"try {\n  ChunkAnnotationUtils.annotateChunk(chunk, attributes);\n} catch (RuntimeException e) {\n  if (e.getMessage().startsWith(\"Unable to annotate attribute\")) {\n    log(\"bad attribute: \" + e.getMessage(), e.getCause());\n  } else throw e;\n}","preventionTips":["Use documented CoreAnnotations key names only","Ensure value strings parse for the key's target type","Inspect getCause() when debugging"],"tags":["stanford-corenlp","reflection","annotation-attributes","type-mismatch"],"backgroundTag":"invalid-argument-value","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"}