Wiki Markup |
---|
Never use assertions to validate arguments of public methods. According to the _Java Language Specification_ , [§14.10, "The {{assert}} Statement"|http://java.sun.com/docs/books/jls/third_edition/html/statements.html#14.10] \[[JLS 2005|AA. Bibliography#JLSReferences#JLS 05]\]: |
...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 problem with using assertions for argument checking is that erroneous arguments should result in an appropriate runtime exception (such as
IllegalArgumentException
,IndexOutOfBoundsException
orNullPointerException
). An assertion failure will not throw an appropriate exception.
...
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="5559b1a98809cb02-b77ea6c0-43b34cd1-97b7b9a5-b16a18afa86c122605eb86a2"><ac:plain-text-body><![CDATA[ | [[Daconta 2003 | AA. Bibliography#Daconta References#Daconta 03]] | Item 7. My assertions are not gratuitous | ]]></ac:plain-text-body></ac:structured-macro> |
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="dd1a5fd47598d7b6-3339f31f-4fb54302-8a9a81a3-a4a6bd44e021cbeda85af6e5"><ac:plain-text-body><![CDATA[ | [[ESA 2005 | AA. Bibliography#ESA References#ESA 05]] | 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 | ]]></ac:plain-text-body></ac:structured-macro> |
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="ff637011fceef7f1-3fb61963-4bb04777-88b2b596-597a1bacdeec1eac9c98f61c"><ac:plain-text-body><![CDATA[ | [[JLS 2005 | AA. Bibliography#JLS References#JLS 05]] | §14.10, The | ]]></ac:plain-text-body></ac:structured-macro> |
...