You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Paul Benedict <pb...@apache.org> on 2009/11/18 07:04:26 UTC

Commons Lang 3: Validate

I would like to make the following changes. Looking for some feedback:

* Append var-args to the method signatures to accept message format
parameters where a message is provided.
* A flag to throw NPE rather IAE on notNull and potentially notEmpty checks

Paul

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


Re: Commons Lang 3: Validate

Posted by Henri Yandell <fl...@gmail.com>.
On Sun, Nov 22, 2009 at 4:36 PM, Stephen Colebourne
<sc...@btopenworld.com> wrote:
> Henri Yandell wrote:
>>
>> On Thu, Nov 19, 2009 at 9:24 AM, Paul Benedict <pb...@apache.org>
>> wrote:
>>>
>>> On Thu, Nov 19, 2009 at 1:39 AM, Henri Yandell <fl...@gmail.com>
>>> wrote:
>>>
>>>> Your argument being that the JDK and others do NPE when null? i.e. NPE
>>>> = IAE(null)?
>>>
>>> Yes. Some things to note:
>>> * The JDK does this as their pattern
>>> * JDK 7 definitely encodes this patter in their new Object.notNull()
>>> method.
>>> * Google Collections -- being a JDK wannabe addition -- does this
>>> * Josuha Bloch's "Effective Java" (two editions) has codified this
>>> expectation into the minds of developers.
>>
>> +1 to NPE.
>
> While I know this is the modern advice, there will be other places where any
> NPE is a bug, and thus Validate should throw IAE.

Other places in the JDK, or in some other library, or that there are
places that choose the non-'modern advice'?

> There are no pretty solutions
> - two classes ValidateNPE and ValidateIAE?

I don't think Validate is that important a class to warrant two impls.

> - some kind of static flag?

Seems brittle. Though a -D property could be doable, that implies
singleton-for-jvm better than just a static flag where people will
want to play funny games with classloaders. Still feels bad though as
wouldn't it mean the API throwing Exception?

> - picking one, and offending the others?

+1 :) I've got better things to do in life than burn time supporting
alternative opinions. Unless the JDK is wrong, JDK wins imo.

Hen

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


Re: Commons Lang 3: Validate

Posted by Paul Benedict <pb...@apache.org>.
Stephen, that's why I thought a static flag would be a compromise, but
I don't think it's the best solution. Anyway, the changes I made
locally so far are this:

* notNull - throws NPE
* isTrue - throws IAE
* isValidIndex - throws IOOBE

Paul

On Sun, Nov 22, 2009 at 6:36 PM, Stephen Colebourne
<sc...@btopenworld.com> wrote:
> Henri Yandell wrote:
>>
>> On Thu, Nov 19, 2009 at 9:24 AM, Paul Benedict <pb...@apache.org>
>> wrote:
>>>
>>> On Thu, Nov 19, 2009 at 1:39 AM, Henri Yandell <fl...@gmail.com>
>>> wrote:
>>>
>>>> Your argument being that the JDK and others do NPE when null? i.e. NPE
>>>> = IAE(null)?
>>>
>>> Yes. Some things to note:
>>> * The JDK does this as their pattern
>>> * JDK 7 definitely encodes this patter in their new Object.notNull()
>>> method.
>>> * Google Collections -- being a JDK wannabe addition -- does this
>>> * Josuha Bloch's "Effective Java" (two editions) has codified this
>>> expectation into the minds of developers.
>>
>> +1 to NPE.
>
> While I know this is the modern advice, there will be other places where any
> NPE is a bug, and thus Validate should throw IAE.
>
> There are no pretty solutions
> - two classes ValidateNPE and ValidateIAE?
> - some kind of static flag?
> - picking one, and offending the others?
>
> Stephen
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
>

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


Re: Commons Lang 3: Validate

Posted by Stephen Colebourne <sc...@btopenworld.com>.
Henri Yandell wrote:
> On Thu, Nov 19, 2009 at 9:24 AM, Paul Benedict <pb...@apache.org> wrote:
>> On Thu, Nov 19, 2009 at 1:39 AM, Henri Yandell <fl...@gmail.com> wrote:
>>
>>> Your argument being that the JDK and others do NPE when null? i.e. NPE
>>> = IAE(null)?
>> Yes. Some things to note:
>> * The JDK does this as their pattern
>> * JDK 7 definitely encodes this patter in their new Object.notNull() method.
>> * Google Collections -- being a JDK wannabe addition -- does this
>> * Josuha Bloch's "Effective Java" (two editions) has codified this
>> expectation into the minds of developers.
> 
> +1 to NPE.

While I know this is the modern advice, there will be other places where 
any NPE is a bug, and thus Validate should throw IAE.

There are no pretty solutions
- two classes ValidateNPE and ValidateIAE?
- some kind of static flag?
- picking one, and offending the others?

Stephen

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


Re: Commons Lang 3: Validate

Posted by Henri Yandell <fl...@gmail.com>.
On Thu, Nov 19, 2009 at 9:24 AM, Paul Benedict <pb...@apache.org> wrote:
> On Thu, Nov 19, 2009 at 1:39 AM, Henri Yandell <fl...@gmail.com> wrote:
>
>> Your argument being that the JDK and others do NPE when null? i.e. NPE
>> = IAE(null)?
>
> Yes. Some things to note:
> * The JDK does this as their pattern
> * JDK 7 definitely encodes this patter in their new Object.notNull() method.
> * Google Collections -- being a JDK wannabe addition -- does this
> * Josuha Bloch's "Effective Java" (two editions) has codified this
> expectation into the minds of developers.

+1 to NPE.

Hen

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


Re: Commons Lang 3: Validate

Posted by Paul Benedict <pb...@apache.org>.
On Thu, Nov 19, 2009 at 1:39 AM, Henri Yandell <fl...@gmail.com> wrote:

> Your argument being that the JDK and others do NPE when null? i.e. NPE
> = IAE(null)?

Yes. Some things to note:
* The JDK does this as their pattern
* JDK 7 definitely encodes this patter in their new Object.notNull() method.
* Google Collections -- being a JDK wannabe addition -- does this
* Josuha Bloch's "Effective Java" (two editions) has codified this
expectation into the minds of developers.

Paul

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


Re: Commons Lang 3: Validate

Posted by Henri Yandell <fl...@gmail.com>.
On Wed, Nov 18, 2009 at 7:40 PM, Paul Benedict <pb...@apache.org> wrote:
> On Wed, Nov 18, 2009 at 12:35 AM, Henri Yandell <fl...@gmail.com> wrote:
>> On Tue, Nov 17, 2009 at 10:04 PM, Paul Benedict <pb...@apache.org> wrote:
>>> I would like to make the following changes. Looking for some feedback:
>>>
>>> * Append var-args to the method signatures to accept message format
>>> parameters where a message is provided.
>>
>> This issue https://issues.apache.org/jira/browse/LANG-508 ?
>
> Yes. Wonderful.

+1 to the change. Feel free to dive in. :)

>>> * A flag to throw NPE rather IAE on notNull and potentially notEmpty checks
>>
>> On the simple path first - can/should we move to NPE?
>>
>
> Sure, I can do simple. My vote is +1 for NPE.

Your argument being that the JDK and others do NPE when null? i.e. NPE
= IAE(null)?

Hen

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


Re: Commons Lang 3: Validate

Posted by Paul Benedict <pb...@apache.org>.
On Wed, Nov 18, 2009 at 12:35 AM, Henri Yandell <fl...@gmail.com> wrote:
> On Tue, Nov 17, 2009 at 10:04 PM, Paul Benedict <pb...@apache.org> wrote:
>> I would like to make the following changes. Looking for some feedback:
>>
>> * Append var-args to the method signatures to accept message format
>> parameters where a message is provided.
>
> This issue https://issues.apache.org/jira/browse/LANG-508 ?

Yes. Wonderful.

>> * A flag to throw NPE rather IAE on notNull and potentially notEmpty checks
>
> On the simple path first - can/should we move to NPE?
>

Sure, I can do simple. My vote is +1 for NPE.

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


Re: Commons Lang 3: Validate

Posted by Henri Yandell <fl...@gmail.com>.
On Tue, Nov 17, 2009 at 10:04 PM, Paul Benedict <pb...@apache.org> wrote:
> I would like to make the following changes. Looking for some feedback:
>
> * Append var-args to the method signatures to accept message format
> parameters where a message is provided.

This issue https://issues.apache.org/jira/browse/LANG-508 ?

> * A flag to throw NPE rather IAE on notNull and potentially notEmpty checks

On the simple path first - can/should we move to NPE?

Hen

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