commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sebb <>
Subject Re: [Math - 403] Never propagate a "NullPointerException" resulting from bad usage of the API
Date Wed, 02 Mar 2011 13:11:48 GMT
On 2 March 2011 12:50, Gilles Sadowski <> wrote:
>> > BTW, you can find precedence in the JVM for many methods that throw NPE on
>> > null arguments. I am not saying this is the "right way", since such things
>> > are subjective and are a matter of design, but many people have concluded
>> > it's better.
>> If the NPE would not be detected until the method has done some other
>> work, then I can seem why one might want to detect it earlier.

The above is the trade-off.

>> And the line number may be insufficient to identify the source of the
>> NPE - there could be several de-references in a single line.
> This is the trade-off which I had mentioned here:

Not really ...

>> >>> In the end, I'm really not sure what is the best approach for this
>> >>> particular case. Personally, I'd be happy that the CM code never checks
>> >>> for
>> >>> null and let the JVM throw NPE. This would hugely simplify the CM code,
>> >>> albeit at the cost of detecting bad usage a little later. IMHO, it is
>> >>> a
>> >>> big deal because the bug is that an object is missing somewhere up the
>> >>> call
>> >>> stack, and it should be corrected there...

.. it may be impossible to determine the true cause of the NPE in some cases.

So in some cases, it makes sense to check for NPE at the start.

> Gilles
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:
> For additional commands, e-mail:

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message