[Date Prev][Date Next]
[Chronological]
[Thread]
[Top]
Passing null to LDAPAttribute constructor (ITS#2683)
Full_Name: Geoffrey Elgey
Version: JLDAP
OS: Linux
URL: ftp://ftp.openldap.org/incoming/
Submission from: (NULL) (202.83.95.124)
No check is made for null in the constructor (as specified in
draft-ietf-ldapext-ldap-java-api-18.txt, section 2.1.1) so the size() method
shall fail with a runtime exception.
LDAPAttribute(com.novell.ldap.LDAPAttribute attr)
{
this.attr = attr;
return;
}
...
public int size()
{
return attr.size();
}
The constructor should be modified as follows:
/**
* Constructs an attribute from a com.novell.ldap.LDAPAttribute
+ *
+ * @param attr the attribute object to be wrapped. Must not be
+ * <code>null</code>.
+ *
+ * @throws IllegalArgumentException if attr is <code>null</code>.
*/
/* package */
LDAPAttribute(com.novell.ldap.LDAPAttribute attr)
{
+ if (attr == null) {
+ throw new IllegalArgumentException("No attribute supplied");
+ }
this.attr = attr;
return;
}
Similarly, all code that calls this constructor should perform appropriate
checks for null values. For example, the org.ietf.ldap.LDAPEntry class should be
modified as follows:
public LDAPAttribute getAttribute(String attrName)
{
- return new LDAPAttribute(entry.getAttribute(attrName));
+ final com.novell.ldap.LDAPAttribute attr =
+ entry.getAttribute(attrName);
+ return (attr != null) ? new LDAPAttribute(attr) : null;
}