Diagnostic tests can be incorporated into programs by using the assert
statement. Assertions are primarily intended for use during debugging and are generally usually turned off before code is deployed by using the -disableassertions
(or -da
) java
runtime option. Consequently, assertions should be used to protect against incorrect programmer assumptions and not for runtime error checking.
...
Code that protects against an input/output error, for example, cannot be implemented as an assertion because it must be presented present in the deployed executable.
...
Because input availability depends on the user and can be exhausted at any point during program execution, a robust program must be prepared to gracefully handle and recover from its exhaustionthe unavailability of input. However, using the assert
statement to verify that some significant input was available is inappropriate because it might lead to an abrupt termination of the process, exposing a DoS vulnerability.
...