{"record":{"id":"fc8ee749f695f2f3","repo":"stanfordnlp/CoreNLP","slug":"cannot-get-min-of-attribute-key-object-of","errorCode":null,"errorMessage":"Cannot get min of attribute \" + key + \", object of type: \" + obj.getClass()","messagePattern":"Cannot get min of attribute \" \\+ key \\+ \", object of type: \" \\+ obj\\.getClass\\(\\)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/pipeline/CoreMapAttributeAggregator.java","lineNumber":204,"sourceCode":"      return sum;\n    }\n  };\n  public static final CoreMapAttributeAggregator MIN = new CoreMapAttributeAggregator() {\n    public Object aggregate(Class key, List<? extends CoreMap> in) {\n      if (in == null) return null;\n      Comparable min = null;\n      for (CoreMap cm:in) {\n        Object obj = cm.get(key);\n        if (obj != null) {\n          if (obj instanceof Comparable) {\n            Comparable c = (Comparable) obj;\n            if (min == null) {\n              min = c;\n            } else if (c.compareTo(min) < 0) {\n              min = c;\n            }\n          } else {\n            throw new RuntimeException(\"Cannot get min of attribute \" + key + \", object of type: \" + obj.getClass());\n          }\n        }\n      }\n      return min;\n    }\n  };\n  public static final CoreMapAttributeAggregator MAX = new CoreMapAttributeAggregator() {\n    public Object aggregate(Class key, List<? extends CoreMap> in) {\n      if (in == null) return null;\n      Comparable max = null;\n      for (CoreMap cm:in) {\n        Object obj = cm.get(key);\n        if (obj != null) {\n          if (obj instanceof Comparable) {\n            Comparable c = (Comparable) obj;\n            if (max == null) {\n              max = c;\n            } else if (c.compareTo(max) > 0) {","sourceCodeStart":186,"sourceCodeEnd":222,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/pipeline/CoreMapAttributeAggregator.java#L186-L222","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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."],"exampleFix":"// before\nObject min = CoreMapAttributeAggregator.MinAggregator.aggregate(maps, CoreAnnotations.SentencesAnnotation.class); // List is not Comparable\n// after\nObject min = CoreMapAttributeAggregator.MinAggregator.aggregate(maps, CoreAnnotations.IndexAnnotation.class); // Integer is Comparable","handlingStrategy":"type-guard","validationCode":"Object v = map.get(key);\nif (v != null && !(v instanceof Comparable)) throw new IllegalStateException(\"Non-comparable value under key: \" + key);","typeGuard":"static boolean isComparable(Object o) { return o instanceof Comparable; }","tryCatchPattern":"try { min = aggregator.aggregate(maps, key); } catch (RuntimeException e) { if (e.getMessage().startsWith(\"Cannot get min\")) { min = minWithComparator(maps, key, myComparator); } else { throw e; } }","preventionTips":["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."],"tags":["stanford-corenlp","aggregation","comparable","type-mismatch"],"backgroundTag":"type-mismatch","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}