directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject [directory-ldap-api] branch master updated: Fix for DIRSERVER-2256 (which is an API issue)
Date Sat, 10 Nov 2018 08:10:04 GMT
This is an automated email from the ASF dual-hosted git repository.

elecharny pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/directory-ldap-api.git


The following commit(s) were added to refs/heads/master by this push:
     new 6f9b650  Fix for DIRSERVER-2256 (which is an API issue)
6f9b650 is described below

commit 6f9b6506290a76b82825079fe198245136821011
Author: elecharny <elecharny@apache.org>
AuthorDate: Sat Nov 10 09:05:37 2018 +0100

    Fix for DIRSERVER-2256 (which is an API issue)
---
 .../api/ldap/model/entry/DefaultAttribute.java       | 18 ++++++++++++++++--
 .../api/ldap/model/entry/AttributeTest.java          | 20 ++++++--------------
 2 files changed, 22 insertions(+), 16 deletions(-)

diff --git a/ldap/model/src/main/java/org/apache/directory/api/ldap/model/entry/DefaultAttribute.java
b/ldap/model/src/main/java/org/apache/directory/api/ldap/model/entry/DefaultAttribute.java
index b1b0557..b38a2b9 100644
--- a/ldap/model/src/main/java/org/apache/directory/api/ldap/model/entry/DefaultAttribute.java
+++ b/ldap/model/src/main/java/org/apache/directory/api/ldap/model/entry/DefaultAttribute.java
@@ -514,9 +514,23 @@ public class DefaultAttribute implements Attribute, Cloneable
     {
         Value value = get();
 
-        if ( isHumanReadable() && ( value != null ) )
+        if ( isHumanReadable() )
         {
-            return value.getValue();
+            if ( value != null )
+            {
+                return value.getValue();
+            }
+            else
+            {
+                return "";
+            }
+        }
+        
+        if ( attributeType == null )
+        {
+            // Special case : the Attribute is not schema aware.
+            // The value is binary, we will try to convert it to a String
+            return Strings.utf8ToString( value.getBytes() );
         }
 
         String message = I18n.err( I18n.ERR_13215_VALUE_EXPECT_STRING );
diff --git a/ldap/model/src/test/java/org/apache/directory/api/ldap/model/entry/AttributeTest.java
b/ldap/model/src/test/java/org/apache/directory/api/ldap/model/entry/AttributeTest.java
index ad87457..74f0a76 100644
--- a/ldap/model/src/test/java/org/apache/directory/api/ldap/model/entry/AttributeTest.java
+++ b/ldap/model/src/test/java/org/apache/directory/api/ldap/model/entry/AttributeTest.java
@@ -50,7 +50,7 @@ import com.mycila.junit.concurrent.ConcurrentJunitRunner;
 
 /**
  * Test the DefaultEntryAttribute class
- * 
+ *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
 @RunWith(ConcurrentJunitRunner.class)
@@ -211,7 +211,7 @@ public class AttributeTest
 
 
     /**
-     * Test method 
+     * Test method
      */
     @Test
     public void testDefaultClientAttributeStringStringArray()
@@ -228,7 +228,7 @@ public class AttributeTest
 
 
     /**
-     * Test method 
+     * Test method
      */
     @Test
     public void testDefaultClientAttributeStringBytesArray()
@@ -296,15 +296,7 @@ public class AttributeTest
 
         attr3.add( BYTES1, BYTES2 );
 
-        try
-        {
-            attr3.getString();
-            fail();
-        }
-        catch ( LdapInvalidAttributeValueException ivae )
-        {
-            assertTrue( true );
-        }
+        assertEquals( "ab", attr3.getString() );
     }
 
 
@@ -1530,8 +1522,8 @@ public class AttributeTest
         assertTrue( dcaSer.contains( password ) );
         assertFalse( dcaSer.isHumanReadable() );
     }
-    
-    
+
+
     /**
      * test that we properly throw an exception, and not a NPE, when no AttributeType is
provided.
      */


Mime
View raw message