stanfordnlp/CoreNLP · error · RuntimeException
Cannot get max of attribute " + key + ", object of type: "…
Error message
Cannot get max of attribute " + key + ", object of type: " + obj.getClass()
What it means
Thrown by the CoreMapAttributeAggregator.MAX aggregate function when an attribute value under the given key is not Comparable, so a maximum cannot be computed across the CoreMaps; indicates a non-comparable object stored under that key.
Solutions
- Use an attribute whose values are Comparable (numbers, strings, dates).
- Normalize values to a Comparable type before aggregation.
- Write a custom Aggregator using an explicit Comparator for non-Comparable types.
Example fix
// before Object max = CoreMapAttributeAggregator.MaxAggregator.aggregate(maps, CoreAnnotations.TokensAnnotation.class); // List not Comparable // after Object max = CoreMapAttributeAggregator.MaxAggregator.aggregate(maps, CoreAnnotations.CharacterOffsetEndAnnotation.class); // Integer
Defensive patterns
Strategy: type-guard
Validate before calling
Object v = map.get(key);
if (v != null && !(v instanceof Comparable)) throw new IllegalStateException("Non-comparable value under key: " + key); Type guard
static boolean isMaxable(Object o) { return o instanceof Comparable; } Try / catch
try { max = aggregator.aggregate(maps, key); } catch (RuntimeException e) { if (e.getMessage().startsWith("Cannot get max")) { max = maxWithComparator(maps, key, myComparator); } else { throw e; } } Prevention
- Apply MAX only to scalar Comparable attributes (offsets, indexes, dates).
- Normalize stored values to a Comparable type during annotation.
- Add startup checks that aggregation keys hold scalar values.
When it happens
Trigger: Calling aggregate with the MAX aggregator on an attribute whose stored values do not implement Comparable (e.g. List, Tree, or arbitrary Object).
Common situations: Applying max aggregation to structural annotations rather than scalar numeric/date/string fields; misconfigured aggregation keys in pipeline or scoring code.
Understand the failure class
Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.
Related errors
- Cannot get min of attribute " + key + ", object of type: "…
- Cannot sum attribute " + key + ", object of type: " +…
- CoreLabels required!
- Expected parsers with DVModel embedded
- This parser does not contain a DVModel reranker
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/2cfd6932d4c04b70.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/pipeline/CoreMapAttributeAggregator.java:226
return min;
}
};
public static final CoreMapAttributeAggregator MAX = new CoreMapAttributeAggregator() {
public Object aggregate(Class key, List<? extends CoreMap> in) {
if (in == null) return null;
Comparable max = null;
for (CoreMap cm:in) {
Object obj = cm.get(key);
if (obj != null) {
if (obj instanceof Comparable) {
Comparable c = (Comparable) obj;
if (max == null) {
max = c;
} else if (c.compareTo(max) > 0) {
max = c;
}
} else {
throw new RuntimeException("Cannot get max of attribute " + key + ", object of type: " + obj.getClass());
}
}
}
return max;
}
};
public static final class MostFreqAggregator extends CoreMapAttributeAggregator {
Set<Object> ignoreSet;
public MostFreqAggregator()
{
}
public MostFreqAggregator(Set<Object> set)
{
ignoreSet = set;
}
View on GitHub (pinned to 1b7edd19c4)