commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ola Berg" <>
Subject Re: [Lang] Assertions?
Date Mon, 21 Oct 2002 15:20:12 GMT
>Case closed! I will go and read up on 1.4.

To myself: Not so quick, young Ola. Here's what the refered document (

* Do not use assertions for argument checking in public methods. 

Argument checking is typically part of the published specifications (or contract) of a method,
and these specifications must be obeyed whether assertions are enabled or disabled. Another
problem with using assertions for argument checking is that erroneous arguments should result
in an appropriate runtime exception (such as IllegalArgumentException, IndexOutOfBoundsException,
or NullPointerException). An assertion failure will not throw an appropriate exception. 

* Do not use assertions to do any work that your application requires for correct operation.

Because assertions may be disabled, programs must not assume that the boolean expression contained
in an assertion will be evaluated.

The use of Assert (or whatever) I thought of would be precisely that illegal use: to faciliate
argument checking in public methods (and throw IAE), in order to enforce object contracts.
If it is easy to enforce a contract, more people will enforce their contracts better and the
amount of stable code in the world will increase.

Assertions as a runtime property will render a lot of the use-cases for assertions useless...
I wonder why they did this?


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

View raw message