stanfordnlp/CoreNLP · error · RuntimeException
Unable to annotate attribute " + key
Error message
Unable to annotate attribute " + key
What it means
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.
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
Example fix
// before
attributes.put("Position", "abc"); // Position is Integer
// after
attributes.put("Position", "5"); Defensive patterns
Strategy: validation
Validate before calling
for (Map.Entry<String,String> e : attributes.entrySet()) {
if (EnvLookup.lookupAnnotationKeyWithClassname(null, e.getKey()) == null)
throw new IllegalArgumentException("Unknown annotation key: " + e.getKey());
} Try / catch
try {
ChunkAnnotationUtils.annotateChunk(chunk, attributes);
} catch (RuntimeException e) {
if (e.getMessage().startsWith("Unable to annotate attribute")) {
log("bad attribute: " + e.getMessage(), e.getCause());
} else throw e;
} Prevention
- Use documented CoreAnnotations key names only
- Ensure value strings parse for the key's target type
- Inspect getCause() when debugging
When it happens
Trigger: 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).
Common situations: 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.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- Unknown field for type , trying to set to
- Incompatible type for type , trying to set to
- Expected parsers with DVModel embedded
- This parser does not contain a DVModel reranker
- Unknown null attribute.
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/00a2b7244863309f.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/pipeline/ChunkAnnotationUtils.java:860
public static void annotateChunk(CoreMap chunk, Map<String,String> attributes) {
for (Map.Entry<String, String> entry : attributes.entrySet()) {
String key = entry.getKey();
String value = entry.getValue();
Class coreKeyClass = AnnotationLookup.toCoreKey(key);
if (key != null) {
if (value != null) {
try {
Class valueClass = AnnotationLookup.getValueType(coreKeyClass);
if (valueClass == String.class) {
chunk.set(coreKeyClass, value);
} else {
Method valueOfMethod = valueClass.getMethod("valueOf", String.class);
if (valueOfMethod != null) {
chunk.set(coreKeyClass, valueOfMethod.invoke(valueClass, value));
}
}
} catch (Exception ex) {
throw new RuntimeException("Unable to annotate attribute " + key, ex);
}
} else {
chunk.set(coreKeyClass, null);
}
} else {
throw new UnsupportedOperationException("Unknown null attribute.");
}
}
}
public static void annotateChunks(List<? extends CoreMap> chunks, int start, int end, Map<String,String> attributes) {
for (int i = start; i < end; i++) {
annotateChunk(chunks.get(i), attributes);
}
}
public static void annotateChunks(List<? extends CoreMap> chunks, Map<String,String> attributes) {
for (CoreMap chunk:chunks) {View on GitHub (pinned to 1b7edd19c4)