mirror of
https://github.com/github/codeql.git
synced 2026-01-31 15:22:57 +01:00
Where possible update Java documentation links to Java 11. Additionally update some other links to use HTTPS.
49 lines
1.3 KiB
XML
49 lines
1.3 KiB
XML
<!DOCTYPE qhelp PUBLIC
|
|
"-//Semmle//qhelp//EN"
|
|
"qhelp.dtd">
|
|
<qhelp>
|
|
|
|
|
|
<overview>
|
|
<p>
|
|
An <code>if-else-if</code> statement without a terminating <code>else</code>
|
|
clause may allow execution to 'fall through' silently, if none of the <code>if</code> clauses are
|
|
matched.
|
|
</p>
|
|
|
|
</overview>
|
|
<recommendation>
|
|
|
|
<p>
|
|
Include a terminating <code>else</code> clause to <code>if-else-if</code> statements
|
|
to prevent execution from falling through silently. If the terminating <code>else</code> clause is
|
|
intended to be unreachable code, it is advisable that it throws a <code>RuntimeException</code> to
|
|
alert the user of an internal error.
|
|
</p>
|
|
|
|
</recommendation>
|
|
<example>
|
|
|
|
<p>In the following example, the <code>if</code> statement outputs the grade that is achieved depending on the
|
|
test score. However, if the score is less than 60, execution falls through silently.</p>
|
|
|
|
<sample src="TerminateIfElseIfWithElse.java" />
|
|
|
|
<p>In the following modified example, the <code>if</code> statement includes a terminating
|
|
<code>else</code> clause, to allow for scores that are less than 60.</p>
|
|
|
|
<sample src="TerminateIfElseIfWithElseGood.java" />
|
|
|
|
</example>
|
|
<references>
|
|
|
|
|
|
<li>
|
|
Java SE Documentation:
|
|
<a href="https://www.oracle.com/java/technologies/javase/codeconventions-statements.html#449">7.4 if, if-else, if else-if else Statements</a>.
|
|
</li>
|
|
|
|
|
|
</references>
|
|
</qhelp>
|