directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1471294 - in /directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/entry: BinaryValue.java StringValue.java
Date Wed, 24 Apr 2013 08:44:21 GMT
Author: elecharny
Date: Wed Apr 24 08:44:21 2013
New Revision: 1471294

URL: http://svn.apache.org/r1471294
Log:
Fixed the readExternal method : if the value has an AttributeType with no Equality atchingRule,
we were having NPE because we weren't testing this case.
This will fix DIRSERVER-1834

Modified:
    directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/entry/BinaryValue.java
    directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/entry/StringValue.java

Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/entry/BinaryValue.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/entry/BinaryValue.java?rev=1471294&r1=1471293&r2=1471294&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/entry/BinaryValue.java
(original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/entry/BinaryValue.java
Wed Apr 24 08:44:21 2013
@@ -236,7 +236,7 @@ public class BinaryValue extends Abstrac
         }
 
         BinaryValue other = ( BinaryValue ) obj;
-        
+
         // First check if we have an attrbuteType.
         if ( attributeType != null )
         {
@@ -260,11 +260,11 @@ public class BinaryValue extends Abstrac
                     {
                         return true;
                     }
-                    
+
                     // We have an AttributeType, we use the associated comparator
                     try
                     {
-                        Comparator<byte[]> comparator = ( Comparator<byte[]>
) getLdapComparator();
+                        Comparator<byte[]> comparator = getLdapComparator();
 
                         // Compare normalized values
                         if ( comparator == null )
@@ -300,22 +300,22 @@ public class BinaryValue extends Abstrac
                 // We have an AttributeType on the base value, we need to use its comparator
                 try
                 {
-                    Comparator<byte[]> comparator = ( Comparator<byte[]> ) getLdapComparator();
+                    Comparator<byte[]> comparator = getLdapComparator();
 
                     // Compare normalized values. We have to normalized the other value,
                     // as it has no AT
                     MatchingRule equality = getAttributeType().getEquality();
-                    
+
                     if ( equality == null )
                     {
                         // No matching rule : compare the raw values
                         return Arrays.equals( getNormReference(), other.getNormReference()
);
                     }
-                    
+
                     Normalizer normalizer = equality.getNormalizer();
-                    
-                    BinaryValue otherValue = (BinaryValue)normalizer.normalize( other );
-                    
+
+                    BinaryValue otherValue = ( BinaryValue ) normalizer.normalize( other
);
+
                     if ( comparator == null )
                     {
                         return Arrays.equals( getNormReference(), otherValue.getNormReference()
);
@@ -343,25 +343,25 @@ public class BinaryValue extends Abstrac
                 {
                     return other.isNull();
                 }
-                
+
                 try
                 {
-                    Comparator<byte[]> comparator = ( Comparator<byte[]> ) other.getLdapComparator();
+                    Comparator<byte[]> comparator = other.getLdapComparator();
 
                     // Compare normalized values. We have to normalized the other value,
                     // as it has no AT
                     MatchingRule equality = other.getAttributeType().getEquality();
-                    
+
                     if ( equality == null )
                     {
                         // No matching rule : compare the raw values
                         return Arrays.equals( getNormReference(), other.getNormReference()
);
                     }
-                    
+
                     Normalizer normalizer = equality.getNormalizer();
-                    
-                    BinaryValue thisValue = (BinaryValue)normalizer.normalize( this );
-                    
+
+                    BinaryValue thisValue = ( BinaryValue ) normalizer.normalize( this );
+
                     if ( comparator == null )
                     {
                         return Arrays.equals( thisValue.getNormReference(), other.getNormReference()
);
@@ -383,7 +383,7 @@ public class BinaryValue extends Abstrac
                 {
                     return other.isNull();
                 }
-                
+
                 // Now check the normalized values
                 return Arrays.equals( getNormReference(), other.getNormReference() );
             }
@@ -558,6 +558,35 @@ public class BinaryValue extends Abstrac
                 try
                 {
                     normalizedValue = attributeType.getEquality().getNormalizer().normalize(
this ).getBytes();
+                    MatchingRule equality = attributeType.getEquality();
+
+                    if ( equality == null )
+                    {
+                        if ( wrappedLength >= 0 )
+                        {
+                            normalizedValue = new byte[wrappedLength];
+
+                            System.arraycopy( wrappedValue, 0, normalizedValue, 0, wrappedLength
);
+                        }
+                    }
+                    else
+                    {
+                        Normalizer normalizer = equality.getNormalizer();
+
+                        if ( normalizer != null )
+                        {
+                            normalizedValue = normalizer.normalize( this ).getBytes();
+                        }
+                        else
+                        {
+                            if ( wrappedLength >= 0 )
+                            {
+                                normalizedValue = new byte[wrappedLength];
+
+                                System.arraycopy( wrappedValue, 0, normalizedValue, 0, wrappedLength
);
+                            }
+                        }
+                    }
                 }
                 catch ( LdapException le )
                 {

Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/entry/StringValue.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/entry/StringValue.java?rev=1471294&r1=1471293&r2=1471294&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/entry/StringValue.java
(original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/entry/StringValue.java
Wed Apr 24 08:44:21 2013
@@ -535,7 +535,25 @@ public class StringValue extends Abstrac
             {
                 try
                 {
-                    normalizedValue = attributeType.getEquality().getNormalizer().normalize(
wrappedValue );
+                    MatchingRule equality = attributeType.getEquality();
+
+                    if ( equality == null )
+                    {
+                        normalizedValue = wrappedValue;
+                    }
+                    else
+                    {
+                        Normalizer normalizer = equality.getNormalizer();
+
+                        if ( normalizer != null )
+                        {
+                            normalizedValue = normalizer.normalize( wrappedValue );
+                        }
+                        else
+                        {
+                            normalizedValue = wrappedValue;
+                        }
+                    }
                 }
                 catch ( LdapException le )
                 {



Mime
View raw message