[jdom-interest] Current test suite failures [eg]

Joseph Bowbeer jozart at csi.com
Sun Apr 15 23:14:00 PDT 2001

philip.nelson at omniresources.com writes:

> These are all various flavors of not handling nulls passed to the add or
> set methods.  In some cases nulls are checked, in some not.
> Sometimes there is no failure at all (until you output anyway).
> Sometimes there is an NPE. I think we need to define this behaviour
> and then code it.  Here is what I suggest.

I'm with you that methods should check parameters and throw exceptions
sooner rather than later.

> 1 - All add methods should check for nulls and throw an
> IllegalAddException if found.

Apparently, the JDK convention is that NullPointerException trumps
IllegalArgumentException (and variants).  At least that's what Josh Bloch
says in Effective Java:

    "If a caller passes null in some parameter for which null values are
prohibited, convention dictates that NullPointerException be thrown rather
than IllegalArgumentException."

> 2 - All set<List> methods like should assume that null means
> the same as Collections.EMPTY_LIST and do that, though I
> imagine that is debatable.

I wonder, too.  Why should we cut null any slack?  Null might also represent
a programmer error.

I suggest we use Collections as a model here.  For example, if you look at
implementations of Collection.addAll(collection), you'll find that they
throw NullPointerException if the Collection argument is null.

Joe Bowbeer

More information about the jdom-interest mailing list