You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by "Waldhoff, Rodney" <rw...@us.britannica.com> on 2002/02/11 05:20:51 UTC

RE: [httpclient] question regarding NameValuePair constructor, nu ll parameters

> Why does the NameValuePair constructor allow
> null parameters?

1. IIRC, there are times we use null attributes.  For example,
NameValuePair("foo",null) is represents "foo" (as a query string or header
element) while NameValuePair("foo","") represtents "foo=".

2. If NameValuePair(String,String) doesn't allow null, what's
NameValuePair() mean?

3. As an abstract pair, why not allow null values, not unlike HashMap.


-----Original Message-----
From: Sean C. Sullivan
To: Jakarta Commons Developers List
Sent: 2/9/02 9:32 PM
Subject: [httpclient] question regarding NameValuePair constructor, null
parameters


Jakarta-commons HttpClient inquiry:

Why does the NameValuePair constructor allow
null parameters?

This is how the code currently looks:

NameValuePair.java

--------------------------

    /**
     * Constructor.
     */
    public NameValuePair(String name, String value) {

        this.name = name;
        this.value = value;

    }

--------------------------

With this constructor, it is allowable for a caller to do this:

    NameValuePair nvp = new NameValuePair(null, null);

I would prefer if the NameValuePair constructor did not allow null
parameters.

I prefer this constructor:

    /**
     * Constructor.
     */
    public NameValuePair(String name, String value) {

        if (null == name) {
            throw new NullPointerException("name parameter is null");
        }
        if (null == value) {
            throw new NullPointerException("value parameter is null");
        }
 
        this.name = name;
        this.value = value;

    }


Regards,

-Sean



--
To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>

Re: [httpclient] question regarding NameValuePair constructor, nu ll parameters

Posted by dIon Gillard <di...@multitask.com.au>.
My take is name should never be null....value on the other hand could 
quite feasibly be null. It is after all a value.

Waldhoff, Rodney wrote:

>>Why does the NameValuePair constructor allow
>>null parameters?
>>
>
>1. IIRC, there are times we use null attributes.  For example,
>NameValuePair("foo",null) is represents "foo" (as a query string or header
>element) while NameValuePair("foo","") represtents "foo=".
>
>2. If NameValuePair(String,String) doesn't allow null, what's
>NameValuePair() mean?
>
>3. As an abstract pair, why not allow null values, not unlike HashMap.
>
>
>-----Original Message-----
>From: Sean C. Sullivan
>To: Jakarta Commons Developers List
>Sent: 2/9/02 9:32 PM
>Subject: [httpclient] question regarding NameValuePair constructor, null
>parameters
>
>
>Jakarta-commons HttpClient inquiry:
>
>Why does the NameValuePair constructor allow
>null parameters?
>
>This is how the code currently looks:
>
>NameValuePair.java
>
>--------------------------
>
>    /**
>     * Constructor.
>     */
>    public NameValuePair(String name, String value) {
>
>        this.name = name;
>        this.value = value;
>
>    }
>
>--------------------------
>
>With this constructor, it is allowable for a caller to do this:
>
>    NameValuePair nvp = new NameValuePair(null, null);
>
>I would prefer if the NameValuePair constructor did not allow null
>parameters.
>
>I prefer this constructor:
>
>    /**
>     * Constructor.
>     */
>    public NameValuePair(String name, String value) {
>
>        if (null == name) {
>            throw new NullPointerException("name parameter is null");
>        }
>        if (null == value) {
>            throw new NullPointerException("value parameter is null");
>        }
> 
>        this.name = name;
>        this.value = value;
>
>    }
>
>
>Regards,
>
>-Sean
>


-- 
dIon Gillard, Multitask Consulting
http://www.multitask.com.au/developers




--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>