Java Reference
In-Depth Information
The NOTREACHED comment could tell some compilers and static analysis tools not to
complain about this unreachable code. It also serves as documentation.
Click here to view code image
if (false) { /* Use of critical security method no
* longer necessary, for now */
/* NOTREACHED */
security_critical_method();
/* Some other comment */
}
This is an example of an exceptional situation described in Guideline 63 , Detect and
remove superfluous code and values .
Applicability
Confusion over which instructions are executed and which are not can result in serious
programming errors and vulnerabilities, including denial of service, abnormal program
termination, and data integrity violation. This problem is mitigated by the use of interact-
ive development environments (IDEs) and editors that use fonts, colors, or other mechan-
isms to differentiate between comments and code. However, the problem can still mani-
fest, for example, when reviewing source code printed on a black-and-white printer.
Nested block comments and inconsistent use of comments can be detected by suitable
static analysis tools.
Bibliography
[JLS 2013]
§3.7, “Comments”
63. Detect and remove superfluous code and values
Superfluous code and values may occur in the form of dead code, code that has no effect,
and unused values in program logic.
Code that is never executed is known as dead code . Typically, the presence of dead
code indicates that a logic error has occurred as a result of changes to a program or to the
program's environment. Dead code is often optimized out of a program during compila-
tion. However, to improve readability and ensure that logic errors are resolved, dead code
should be identified, understood, and removed.
Search WWH ::




Custom Search