{"record":{"id":"89db421735404ed0","repo":"spring-projects/spring-security","slug":"invalid-object-type-value-getclass-getname","errorCode":null,"errorMessage":"Invalid object type: {value.getClass().getName()}","messagePattern":"Invalid object type: (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/springframework/security/core/authority/mapping/MapBasedAttributes2GrantedAuthoritiesMapper.java","lineNumber":143,"sourceCode":"\t */\n\tprivate void addGrantedAuthorityCollection(Collection<GrantedAuthority> result, @Nullable Object value) {\n\t\tif (value == null) {\n\t\t\treturn;\n\t\t}\n\t\tif (value instanceof Collection<?>) {\n\t\t\taddGrantedAuthorityCollection(result, (Collection<?>) value);\n\t\t}\n\t\telse if (value instanceof Object[]) {\n\t\t\taddGrantedAuthorityCollection(result, (Object[]) value);\n\t\t}\n\t\telse if (value instanceof String) {\n\t\t\taddGrantedAuthorityCollection(result, (String) value);\n\t\t}\n\t\telse if (value instanceof GrantedAuthority) {\n\t\t\tresult.add((GrantedAuthority) value);\n\t\t}\n\t\telse {\n\t\t\tthrow new IllegalArgumentException(\"Invalid object type: \" + value.getClass().getName());\n\t\t}\n\t}\n\n\tprivate void addGrantedAuthorityCollection(Collection<GrantedAuthority> result, Collection<?> value) {\n\t\tfor (Object elt : value) {\n\t\t\taddGrantedAuthorityCollection(result, elt);\n\t\t}\n\t}\n\n\tprivate void addGrantedAuthorityCollection(Collection<GrantedAuthority> result, Object[] value) {\n\t\tfor (Object aValue : value) {\n\t\t\taddGrantedAuthorityCollection(result, aValue);\n\t\t}\n\t}\n\n\tprivate void addGrantedAuthorityCollection(Collection<GrantedAuthority> result, String value) {\n\t\tStringTokenizer tokenizer = new StringTokenizer(value, this.stringSeparator, false);\n\t\twhile (tokenizer.hasMoreTokens()) {","sourceCodeStart":125,"sourceCodeEnd":161,"githubUrl":"https://github.com/spring-projects/spring-security/blob/96852e8860138a482cb13d1479573f24ff6443c6/core/src/main/java/org/springframework/security/core/authority/mapping/MapBasedAttributes2GrantedAuthoritiesMapper.java#L125-L161","documentation":"MapBasedAttributes2GrantedAuthoritiesMapper converts user attribute values into GrantedAuthority instances. Its per-element conversion accepts String, Collection, or GrantedAuthority; any other object type hits the else branch and throws IllegalArgumentException naming the offending class.","triggerScenarios":"Calling getGrantedAuthorityCollection/addGrantedAuthorityCollection with an attribute map whose values (or elements inside a collection value) are not String, Collection, or GrantedAuthority — e.g. Integer, Boolean, or a nested List of numbers from an LDAP/DB attribute source.","commonSituations":"Mapping directory attributes (like memberOf returning non-string objects) to authorities; passing raw numbers from a database role column; supplying a List<List<String>> nested structure.","solutions":["Convert non-string attribute values to String (e.g. String.valueOf(value)) before mapping","Ensure collection values contain only strings/GrantedAuthorities — flatten or stringify nested collections","Add a custom Attributes2GrantedAuthoritiesMapper implementation that handles your value types"],"exampleFix":"// before\nMap<String, Object> attrs = Map.of(\"role\", 42);\nmapper.getGrantedAuthorities(attrs);\n// after\nMap<String, Object> attrs = Map.of(\"role\", String.valueOf(42));\nmapper.getGrantedAuthorities(attrs);","handlingStrategy":"validation","validationCode":"Object v = attrs.get(\"role\"); if (!(v instanceof String || v instanceof GrantedAuthority || v instanceof Collection)) throw new IllegalArgumentException(\"unsupported attribute type: \" + v.getClass());","typeGuard":"boolean mappable(Object v) { return v instanceof String || v instanceof GrantedAuthority || v instanceof Collection<?>; }","tryCatchPattern":"try { authorities = mapper.getGrantedAuthorities(attrs); } catch (IllegalArgumentException ex) { authorities = List.of(); }","preventionTips":["Ensure all attribute values are String, GrantedAuthority, or Collection of those","Stringify non-string DB/LDAP values before mapping","Flatten nested collections before mapping","Write unit tests covering all attribute types your source returns"],"tags":["type-mismatch","authority-mapping","illegal-argument"],"backgroundTag":"type-mismatch","analyzedSha":"96852e8860138a482cb13d1479573f24ff6443c6","analyzedAt":"2026-09-10T23:25:23.477Z","contentChangedAt":"2026-09-10T23:25:23.477Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}