tom.hawtin at oracle.com
Thu Jan 13 21:12:26 UTC 2011
On 13/01/2011 20:06, Brian Goetz wrote:
> Most of the other methods in this class are of the form "do the right
> thing if the object is null (or an array)", but this one is "throw an
> exception if the object is null." The intent is clear -- it is for
> simplifying fail-fast behavior by checking for nullity early -- but the
> name is wrong. This is bad for two reasons: (a) it is confusing and (b)
> it forecloses on using the name nonNull() for what most people expect it
> to do -- which is provide a reasonable default.
I think this is completely the wrong way around. On encountering a null
the right thing is to throw an NPE. Don't make Sir C.A.R. Hoare's
billion-dollar mistake worse.
Perhaps the carpet-sweeping methods should be renamed, or put into an
appropriately named class.
More information about the core-libs-dev