Skip to content

LDAP-343: DirContextAdapter incorrectly throws IllegalArgumentException when adding Name attributes #375

@spring-projects-issues

Description

@spring-projects-issues

Krzysztof Pado (Migrated from LDAP-343) said:

addAttributeValue method of DirContextAdapter fails with "java.lang.IllegalArgumentException: This instance has non-string attribute values; cannot handle Name values" when value of Name type is passed as value parameter, if previously another Name value was added.

The following code fails at line 3:
{{1: DirContextOperations operations = new DirContextAdapter("CN=group,DC=root");
2: operations.addAttributeValue("member", LdapUtils.newLdapName("CN=test,DC=root"));
3: operations.addAttributeValue("member", LdapUtils.newLdapName("CN=test2,DC=root"));}}

However, when first attribute is set as string, not as Name it runs fine:
{{1: DirContextOperations operations = new DirContextAdapter("CN=group,DC=root");
2: operations.addAttributeValue("member", "CN=test,DC=root");
3: operations.addAttributeValue("member", LdapUtils.newLdapName("CN=test2,DC=root"));}}

Technical analysis:
In NameAwareAttribute(String id, Object value) constructor value is added to values field, but there is no check whether value is instance of a Name, and initValuesAsNames method is not called. This causes an error in next public boolean add(Object attrVal) invocation with attrVal of type Name.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions