Added a check for empty attribute. LDAP-215

This commit is contained in:
Ulrik Sandberg
2010-09-25 21:25:18 +00:00
parent ca1d6e3dab
commit 5b662eff8c
2 changed files with 14 additions and 1 deletions

View File

@@ -558,7 +558,7 @@ public class DirContextAdapter implements DirContextOperations {
*/
public Object getObjectAttribute(String name) {
Attribute oneAttr = originalAttrs.get(name);
if (oneAttr == null) {
if (oneAttr == null || oneAttr.size() == 0) { // LDAP-215
return null;
}
try {

View File

@@ -83,6 +83,19 @@ public class DirContextAdapterTest extends TestCase {
assertNull(s);
}
public void testGetStringAttributeDoesExistButWithNoValue() throws Exception {
final Attributes attrs = new BasicAttributes();
attrs.put(new BasicAttribute("abc"));
class TestableDirContextAdapter extends DirContextAdapter {
public TestableDirContextAdapter() {
super(attrs, null);
}
}
tested = new TestableDirContextAdapter();
String s = tested.getStringAttribute("abc");
assertNull(s);
}
public void testGetStringAttributeExists() throws Exception {
final Attributes attrs = new BasicAttributes();
attrs.put(new BasicAttribute("abc", "def"));