commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Rand McNeely" <rand_mcne...@yahoo.com>
Subject HttpClient NullPointerException in equals(Object o) of org.apache.commons.httpclient.NameValuePair
Date Sat, 29 Jun 2002 17:09:43 GMT
This is my first contribution to a Jakarta project, if I am in poor
form, let me know.

Before calling object.getClass(), check to see if passed object is null.

    /**
     * Test if the given <i>object</i> is equal to me.
     * In this implementation, an <i>object</i> is
     * equal to me iff it has the same runtime
     * type and the <i>name</i> and <i>value</i> attributes
     * are both <tt>equal</tt> (or <tt>==</tt>).
     *
     * @param object the {@link Object} to compare to
     */
    public boolean equals(Object object) {
        if (this == object) {
            return true;
        } else if (null == object) {
            return false;
        } else if (this.getClass().equals(object.getClass())) {
            NameValuePair pair = (NameValuePair) object;
            return ((null == name ? null == pair.name :
name.equals(pair.name))
                   && (null == value ? null == pair.value :
value.equals(pair.value)));
        } else {
            return false;
        }
    }

Thanks,
Rand


--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message