You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2019/05/09 22:36:44 UTC

[directory-ldap-api] branch master updated: o Removed some calls to value.getString() which weren't necessary o Fixed some potential error when using the Value.getString() method on binary values

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 0e116e9  o Removed some calls to value.getString() which weren't necessary o Fixed some potential error when using the Value.getString() method on binary values
0e116e9 is described below

commit 0e116e9f582caa288c3dd4204f5c87c171e198a8
Author: emmanuel lecharny <el...@apache.org>
AuthorDate: Fri May 10 00:36:39 2019 +0200

    o Removed some calls to value.getString() which weren't necessary
    o Fixed some potential error when using the Value.getString() method on
    binary values
---
 .../directory/api/ldap/model/entry/AttributeUtils.java   | 10 +++++++++-
 .../org/apache/directory/api/ldap/model/entry/Value.java |  4 ++--
 .../directory/api/ldap/model/ldif/LdifRevertor.java      | 10 +++++-----
 .../org/apache/directory/api/ldap/model/name/Ava.java    | 10 +---------
 .../api/ldap/schema/loader/SchemaEntityFactory.java      | 16 +---------------
 5 files changed, 18 insertions(+), 32 deletions(-)

diff --git a/ldap/model/src/main/java/org/apache/directory/api/ldap/model/entry/AttributeUtils.java b/ldap/model/src/main/java/org/apache/directory/api/ldap/model/entry/AttributeUtils.java
index e9af219..14ae2b9 100644
--- a/ldap/model/src/main/java/org/apache/directory/api/ldap/model/entry/AttributeUtils.java
+++ b/ldap/model/src/main/java/org/apache/directory/api/ldap/model/entry/AttributeUtils.java
@@ -758,7 +758,15 @@ public final class AttributeUtils
             for ( Iterator<Value> valueIterator = attribute.iterator(); valueIterator.hasNext(); )
             {
                 Value value = valueIterator.next();
-                jndiAttribute.add( value.getString() );
+                
+                if ( value.isHumanReadable() )
+                {
+                    jndiAttribute.add( value.getString() );
+                }
+                else
+                {
+                    jndiAttribute.add( value.getBytes() );
+                }
             }
 
             return jndiAttribute;
diff --git a/ldap/model/src/main/java/org/apache/directory/api/ldap/model/entry/Value.java b/ldap/model/src/main/java/org/apache/directory/api/ldap/model/entry/Value.java
index 2414943..78c5735 100644
--- a/ldap/model/src/main/java/org/apache/directory/api/ldap/model/entry/Value.java
+++ b/ldap/model/src/main/java/org/apache/directory/api/ldap/model/entry/Value.java
@@ -581,8 +581,8 @@ public class Value implements Cloneable, Externalizable, Comparable<Value>
 
 
     /**
-     * Get the wrapped value as a byte[]. If the original value
-     * is binary, this method will return a copy of the wrapped byte[]
+     * Get the wrapped value as a byte[], if and only if the Value is binary,
+     * otherwise returns null.
      *
      * @return the wrapped value as a byte[]
      */
diff --git a/ldap/model/src/main/java/org/apache/directory/api/ldap/model/ldif/LdifRevertor.java b/ldap/model/src/main/java/org/apache/directory/api/ldap/model/ldif/LdifRevertor.java
index 22b03d8..96fd2a3 100644
--- a/ldap/model/src/main/java/org/apache/directory/api/ldap/model/ldif/LdifRevertor.java
+++ b/ldap/model/src/main/java/org/apache/directory/api/ldap/model/ldif/LdifRevertor.java
@@ -383,13 +383,13 @@ public final class LdifRevertor
         {
             // No need to add something which has already been added
             // in the previous modification
-            if ( !entry.contains( ava.getNormType(), ava.getValue().getString() )
-                && !( ava.getNormType().equals( oldRdn.getNormType() ) && ava.getValue().getString().equals(
+            if ( !entry.contains( ava.getNormType(), ava.getValue() )
+                && !( ava.getNormType().equals( oldRdn.getNormType() ) && ava.getValue().equals(
                     oldRdn.getValue() ) ) )
             {
                 // Create the modification, which is an Remove
                 Modification modification = new DefaultModification( ModificationOperation.REMOVE_ATTRIBUTE,
-                    new DefaultAttribute( ava.getType(), ava.getValue().getString() ) );
+                    new DefaultAttribute( ava.getType(), ava.getValue() ) );
 
                 restored.addModification( modification );
             }
@@ -525,7 +525,7 @@ public final class LdifRevertor
                 for ( Ava atav : newRdn )
                 {
                     if ( !atav.equals( oldRdn.getAva() )
-                        && ( entry.contains( atav.getNormType(), atav.getValue().getString() ) ) )
+                        && ( entry.contains( atav.getNormType(), atav.getValue() ) ) )
                     {
                         existInEntry = true;
                     }
@@ -578,7 +578,7 @@ public final class LdifRevertor
                     {
                         overlapping = true;
                     }
-                    else if ( entry.contains( atav.getNormType(), atav.getValue().getString() ) )
+                    else if ( entry.contains( atav.getNormType(), atav.getValue() ) )
                     {
                         existInEntry = true;
                     }
diff --git a/ldap/model/src/main/java/org/apache/directory/api/ldap/model/name/Ava.java b/ldap/model/src/main/java/org/apache/directory/api/ldap/model/name/Ava.java
index df5febf..cafbf51 100644
--- a/ldap/model/src/main/java/org/apache/directory/api/ldap/model/name/Ava.java
+++ b/ldap/model/src/main/java/org/apache/directory/api/ldap/model/name/Ava.java
@@ -172,15 +172,7 @@ public class Ava implements Externalizable, Cloneable, Comparable<Ava>
             }
         }
         
-        StringBuilder sb = new StringBuilder( upType );
-        sb.append( '=' );
-        
-        if ( ( value != null ) && ( value.getString() != null ) )
-        {
-            sb.append( value.getString() );
-        }
-        
-        upName = sb.toString();
+        upName = getEscaped();
 
         hashCode();
     }
diff --git a/ldap/schema/data/src/main/java/org/apache/directory/api/ldap/schema/loader/SchemaEntityFactory.java b/ldap/schema/data/src/main/java/org/apache/directory/api/ldap/schema/loader/SchemaEntityFactory.java
index 7ca7bff..bc0aef1 100644
--- a/ldap/schema/data/src/main/java/org/apache/directory/api/ldap/schema/loader/SchemaEntityFactory.java
+++ b/ldap/schema/data/src/main/java/org/apache/directory/api/ldap/schema/loader/SchemaEntityFactory.java
@@ -1359,20 +1359,6 @@ public class SchemaEntityFactory implements EntityFactory
 
 
     /**
-     * Return a String value, from the given Value, even if it's a binary value
-     * 
-     * @param attribute The Attribute to process
-     * @return The Attribute value as a String
-     */
-    private String getStringValue( Attribute attribute )
-    {
-        Value value = attribute.get();
-
-        return value.getString();
-    }
-
-
-    /**
      * Process the common attributes to all SchemaObjects :
      *  - obsolete
      *  - description
@@ -1405,7 +1391,7 @@ public class SchemaEntityFactory implements EntityFactory
 
         if ( mDescription != null )
         {
-            schemaObject.setDescription( getStringValue( mDescription ) );
+            schemaObject.setDescription( mDescription.getString() );
         }
 
         // The names field