Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Reverted from v. 36

Never use assertions to validate arguments of public methods. The Java Language Specification, §14.10, "The assert Statement" [JLS 20052015], states that

assertions should not be used for argument - checking in public methods. Argument - checking is typically part of the contract of a method, and this contract must be upheld whether assertions are enabled or disabled.

Another A secondary problem with using assertions for argument checking is that erroneous arguments should result in an appropriate runtime run-time exception (such as IllegalArgumentException, IndexOutOfBoundsException, or NullPointerException). An assertion failure will not throw an appropriate exception.

...

[Daconta 2003]

Item 7, "My Assertions Are Not gratuitous"

[ESA 2005]

Rule 68. , Explicitly check method parameters for validity, and throw an adequate exception in case they are not valid. Do not use the assert statement for this purpose

[JLS 20052015]

§14.10, "The assert Statement"

 

...