commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Phil Steitz <>
Subject Re: [math] Restoring IAE to MathUtils#binomialCoefficient methods
Date Sun, 01 May 2011 15:34:31 GMT
On 5/1/11 6:00 AM, Gilles Sadowski wrote:
> On Sun, May 01, 2011 at 12:48:14PM +0200, Gilles Sadowski wrote:
>> On Sat, Apr 30, 2011 at 10:53:30PM -0700, Phil Steitz wrote:
>>> On 4/30/11 4:33 PM, Gilles Sadowski wrote:
>>>> On Sat, Apr 30, 2011 at 09:10:08AM -0700, Phil Steitz wrote:
>>>>> Converting some of my code to use trunk, I discovered that the
>>>>> binomialCoefficient methods no longer throw IllegalArgumentException
>>>>> when parameters are invalid.
>>>> The consensus was a singly rooted hierarchy ("MathRuntimeException").
>>>> The advantage being commonly agreed on was to offer the "map" functionality
>>>> for adding messages and context information.
>>> I guess I misunderstood and after really seeing the consequences in
>>> my own code, I am going to have to ask that we reopen that
>>> discussion - i.e., I would like us to throw IAE and other standard
>>> exceptions where appropriate, as in this case, as we have up to and
>>> through 2.2.  I know I said before that I did not see this as worth
>>> arguing about, but I really think this change is a bad API design
>>> decision that will cause needless hassle and surprising RTEs for
>>> users upgrading to the new version.
>> I'm astonished, and for the time being, will refrain from other comments.
> There is no one single best API design. What counts most IMO is that it is
> consistent and leads to clean and lean code.
> The old exception factories à la
> -----
>   MathRuntimeException.createIllegalArgumentException("Error with an argument {0}", x);
> -----
> failed on all accounts.
> Now, I would like to settle this issue once for all. Should all CM
> exceptions inherit from the standard Java exceptions hierarchies (rooted at
> IAE, UOE, NPE, AE, etc.)?  Although it had been answered "no" previously, it
> was not my preferred choice. I could make it "yes" now but I'd rather not
> changed that back and forth again and again.'
I apologize sincerely for opening this up again.  I don't think
*all* exceptions thrown by [math] should derive from standard
exceptions, other than I guess Exception itself.  I do think,
however, that [math] *should* throw standard exceptions directly
when appropriate and in general favor standard exceptions.  In
particular, I would prefer that we revert to the 1.0-2.2 behavior of
throwing IllegalArgumentException when preconditions are violated. 
I personally have no problem with using the exception factories and
will volunteer to retrofit the code if we can agree to this change.

Once again, I hate to flip-flop, but this is an important and
impactful decision and I have now experienced the upgrade pain
(unexpected RTEs when upgrading) directly so would like to ask that
we revisit it.

To be clear, my opinion is that for all of the RTEs currently
generated by MathRuntimeException.createXxxException, we should
generate and throw these exceptions directly, as appropriate, using
the factory to enable localization.

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

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

View raw message