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 DIRAPI-302. We now throw an IllegalArgumentException instead of a NPE.
Date Mon, 09 Apr 2018 16:46:47 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 3c6a765  Fix for DIRAPI-302. We now throw an IllegalArgumentException instead of
a NPE.
3c6a765 is described below

commit 3c6a7652e171772dbc0c55042ad10260002002b9
Author: Emmanuel L├ęcharny <elecharny@symas.com>
AuthorDate: Mon Apr 9 18:46:45 2018 +0200

    Fix for DIRAPI-302. We now throw an IllegalArgumentException instead of
    a NPE.
---
 .../org/apache/directory/api/ldap/model/entry/Value.java     |  5 ++++-
 .../apache/directory/api/ldap/model/entry/AttributeTest.java | 12 ++++++++++++
 2 files changed, 16 insertions(+), 1 deletion(-)

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 ca7c8ab..7bb5bb4 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
@@ -32,6 +32,7 @@ import org.apache.directory.api.ldap.model.exception.LdapInvalidAttributeValueEx
 import org.apache.directory.api.ldap.model.message.ResultCodeEnum;
 import org.apache.directory.api.ldap.model.schema.AttributeType;
 import org.apache.directory.api.ldap.model.schema.LdapComparator;
+import org.apache.directory.api.ldap.model.schema.LdapSyntax;
 import org.apache.directory.api.ldap.model.schema.MatchingRule;
 import org.apache.directory.api.ldap.model.schema.Normalizer;
 import org.apache.directory.api.ldap.model.schema.SyntaxChecker;
@@ -269,7 +270,9 @@ public class Value implements Cloneable, Externalizable, Comparable<Value>
         if ( !attributeType.isRelaxed() )
         {
             // Check the value
-            if ( attributeType.getSyntax().getSyntaxChecker() != null )
+            LdapSyntax syntax = attributeType.getSyntax();
+            
+            if ( ( syntax != null ) && ( syntax.getSyntaxChecker() != null ) ) 
             {
                 if ( !attributeType.getSyntax().getSyntaxChecker().isValidSyntax( upValue
) )
                 {
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 966eced..5263347 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
@@ -38,6 +38,7 @@ import javax.naming.directory.InvalidAttributeValueException;
 
 import org.apache.directory.api.ldap.model.exception.LdapException;
 import org.apache.directory.api.ldap.model.exception.LdapInvalidAttributeValueException;
+import org.apache.directory.api.ldap.model.schema.AttributeType;
 import org.apache.directory.api.util.Strings;
 import org.junit.BeforeClass;
 import org.junit.Test;
@@ -1529,4 +1530,15 @@ 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.
+     */
+    @Test( expected=IllegalArgumentException.class )
+    public void testNullAT() throws LdapInvalidAttributeValueException
+    {
+        AttributeType attributeType = new AttributeType("mail");
+        Value stringValue = new Value(attributeType, "test@test.com");
+    }
 }

-- 
To stop receiving notification emails like this one, please contact
elecharny@apache.org.

Mime
View raw message