Skip to content

Commit

Permalink
SONARJAVA-1546 Update description
Browse files Browse the repository at this point in the history
  • Loading branch information
Wohops committed Feb 22, 2016
1 parent 2294b19 commit c2ddc76
Showing 1 changed file with 22 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<p>Returning from a <code>finally</code> block suppresses the propagation of any unhandled <code>Throwable</code> which was thrown in the <code>try</code> or <code>catch</code> block.</p>
<h2>Noncompliant Code Example</h2>
<p><code>return</code>ing, <code>break</code>ing, <code>throw</code>ing, and so on from a <code>finally</code> block suppresses the propagation of any unhandled <code>Throwable</code> which was thrown in the <code>try</code> or <code>catch</code> block.</p>
<p>This rule raises an issue when a jump statement (<code>break</code>, <code>continue</code>, <code>return</code>, <code>throw</code>, and <code>goto</code>) would force control flow to leave a <code>finally</code> block. </p>

<h2>Noncompliant Code Example</h2>
<pre>
public static void main(String[] args) {
try {
Expand All @@ -15,6 +16,13 @@ <h2>Noncompliant Code Example</h2>
try {
throw new RuntimeException();
} finally {
for (int i = 0; i &lt; 10; i ++) {
//...
if (q == i) {
break; // ignored
}
}

/* ... */
return; // Noncompliant - prevents the RuntimeException from being propagated
}
Expand All @@ -36,12 +44,21 @@ <h2>Compliant Solution</h2>
try {
throw new RuntimeException();
} finally {
for (int i = 0; i &lt; 10; i ++) {
//...
if (q == i) {
break; // ignored
}
}

/* ... */
}
}
</pre>
<h2>See</h2>

<h2>See</h2>
<ul>
<li><a href="http://cwe.mitre.org/data/definitions/584.html">MITRE, CWE-584</a> - Return Inside Finally Block</li>
</ul>
<li> <a href="http://cwe.mitre.org/data/definitions/584.html">MITRE, CWE-584</a> - Return Inside Finally Block
</li><li> <a href="https://www.securecoding.cert.org/confluence/x/mIEbAQ">CERT, ERR04-J.</a> - Do not complete abruptly from a finally block
</li></ul>

0 comments on commit c2ddc76

Please sign in to comment.