diff --git a/core/src/main/java/org/springframework/ldap/core/DirContextAdapter.java b/core/src/main/java/org/springframework/ldap/core/DirContextAdapter.java index 74315921..62bc04d7 100644 --- a/core/src/main/java/org/springframework/ldap/core/DirContextAdapter.java +++ b/core/src/main/java/org/springframework/ldap/core/DirContextAdapter.java @@ -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 { diff --git a/core/src/test/java/org/springframework/ldap/core/DirContextAdapterTest.java b/core/src/test/java/org/springframework/ldap/core/DirContextAdapterTest.java index 6fd15c16..d0350ed6 100644 --- a/core/src/test/java/org/springframework/ldap/core/DirContextAdapterTest.java +++ b/core/src/test/java/org/springframework/ldap/core/DirContextAdapterTest.java @@ -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"));