stanfordnlp/CoreNLP · error · RuntimeException
Cannot get min of attribute " + key + ", object of type: "…
Error message
Cannot get min of attribute " + key + ", object of type: " + obj.getClass()
What it means
The MIN aggregator requires each value for the attribute key to implement Comparable; it casts to Comparable and compares. If the stored object is not Comparable it throws a RuntimeException stating the type cannot be min'd.
Solutions
- Aggregate over an attribute whose values are Comparable (Integer, Double, String, etc.).
- Convert values to a Comparable type before aggregating.
- Provide a custom aggregator with an explicit Comparator for the type.
Example fix
// before Object min = CoreMapAttributeAggregator.MinAggregator.aggregate(maps, CoreAnnotations.SentencesAnnotation.class); // List is not Comparable // after Object min = CoreMapAttributeAggregator.MinAggregator.aggregate(maps, CoreAnnotations.IndexAnnotation.class); // Integer is Comparable
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 isComparable(Object o) { return o instanceof Comparable; } Try / catch
try { min = aggregator.aggregate(maps, key); } catch (RuntimeException e) { if (e.getMessage().startsWith("Cannot get min")) { min = minWithComparator(maps, key, myComparator); } else { throw e; } } Prevention
- Reserve min/max aggregation for Comparable-typed attributes.
- Convert values to Integer/Double/String before storing them on the CoreMap.
- Write a custom aggregator with an explicit Comparator for complex types.
When it happens
Trigger: Calling aggregate with the MIN aggregator on an attribute whose values are not Comparable objects (e.g. a raw Object, List, or Tree stored under the key).
Common situations: Selecting a coref/map key for min aggregation where values are complex types; using MIN on textual annotations whose runtime type does not implement Comparable.
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 max 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/fc8ee749f695f2f3.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/pipeline/CoreMapAttributeAggregator.java:204
return sum;
}
};
public static final CoreMapAttributeAggregator MIN = new CoreMapAttributeAggregator() {
public Object aggregate(Class key, List<? extends CoreMap> in) {
if (in == null) return null;
Comparable min = null;
for (CoreMap cm:in) {
Object obj = cm.get(key);
if (obj != null) {
if (obj instanceof Comparable) {
Comparable c = (Comparable) obj;
if (min == null) {
min = c;
} else if (c.compareTo(min) < 0) {
min = c;
}
} else {
throw new RuntimeException("Cannot get min of attribute " + key + ", object of type: " + obj.getClass());
}
}
}
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) {View on GitHub (pinned to 1b7edd19c4)