From 5b662eff8ca743c90275343a5adecb3043462cd2 Mon Sep 17 00:00:00 2001 From: Ulrik Sandberg Date: Sat, 25 Sep 2010 21:25:18 +0000 Subject: [PATCH] Added a check for empty attribute. LDAP-215 --- .../ldap/core/DirContextAdapter.java | 2 +- .../ldap/core/DirContextAdapterTest.java | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) 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"));