{"record":{"id":"2cfd6932d4c04b70","repo":"stanfordnlp/CoreNLP","slug":"cannot-get-max-of-attribute-key-object-of","errorCode":null,"errorMessage":"Cannot get max of attribute \" + key + \", object of type: \" + obj.getClass()","messagePattern":"Cannot get max 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":226,"sourceCode":"      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) {\n              max = c;\n            }\n          } else {\n            throw new RuntimeException(\"Cannot get max of attribute \" + key + \", object of type: \" + obj.getClass());\n          }\n        }\n      }\n      return max;\n    }\n  };\n\n  public static final class MostFreqAggregator extends CoreMapAttributeAggregator {\n    Set<Object> ignoreSet;\n    public MostFreqAggregator()\n    {\n    }\n\n    public MostFreqAggregator(Set<Object> set)\n    {\n      ignoreSet = set;\n    }\n","sourceCodeStart":208,"sourceCodeEnd":244,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/pipeline/CoreMapAttributeAggregator.java#L208-L244","documentation":"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.","triggerScenarios":"Calling aggregate with the MAX aggregator on an attribute whose stored values do not implement Comparable (e.g. List, Tree, or arbitrary Object).","commonSituations":"Applying max aggregation to structural annotations rather than scalar numeric/date/string fields; misconfigured aggregation keys in pipeline or scoring code.","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."],"exampleFix":"// before\nObject max = CoreMapAttributeAggregator.MaxAggregator.aggregate(maps, CoreAnnotations.TokensAnnotation.class); // List not Comparable\n// after\nObject max = CoreMapAttributeAggregator.MaxAggregator.aggregate(maps, CoreAnnotations.CharacterOffsetEndAnnotation.class); // Integer","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 isMaxable(Object o) { return o instanceof Comparable; }","tryCatchPattern":"try { max = aggregator.aggregate(maps, key); } catch (RuntimeException e) { if (e.getMessage().startsWith(\"Cannot get max\")) { max = maxWithComparator(maps, key, myComparator); } else { throw e; } }","preventionTips":["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."],"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"}