commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Paul Cantrell <>
Subject Re: [Lang] Assertions?
Date Mon, 21 Oct 2002 18:28:26 GMT
> Actually, I think I throw all of these as IAEs. ... The reality is 
> that the state version, throwing IllegalStateException, is hardly ever 
> used

Perhaps by you. But speak for yourself! :)

I actually use IllegalStateException rather often, and 
UnsupportedOperation on occasion.  Clearly, IAE would be totally 
inappropriate from, say, the no-args remove() method on an iterator:

     public void remove()
         if(curElem == null)
             throw new IllegalArgumentException("iterator is already 
past end of collection");
             // Above makes no sense: What illegal argument?!

However, IAE is by far the most common, and it is almost always the 
case that IAE is appropriate for validation.  So I think we could both 
agree that methods on Validate could be explicitly designed for 
checking arguments, and throw IAE.  That certainly seems reasonable to 

The only danger here is that while while the code above is quite 
obviously wrong, the following code has exactly the same problem, but 
it's much less obvious:

     public void remove()
         Validator.isNotNull(curElem, "iterator is already past end of 

That's why it would probably be best to choose a method name which made 
it clear that the method is for argument validation, not null checking 
in general.



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

View raw message