Skip to content

Commit c2ddc76

Browse files
committed
SONARJAVA-1546 Update description
1 parent 2294b19 commit c2ddc76

1 file changed

Lines changed: 22 additions & 5 deletions

File tree

  • java-checks/src/main/resources/org/sonar/l10n/java/rules/squid

java-checks/src/main/resources/org/sonar/l10n/java/rules/squid/S1143.html

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
<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>
2-
<h2>Noncompliant Code Example</h2>
1+
<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>
2+
<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>
33

4+
<h2>Noncompliant Code Example</h2>
45
<pre>
56
public static void main(String[] args) {
67
try {
@@ -15,6 +16,13 @@ <h2>Noncompliant Code Example</h2>
1516
try {
1617
throw new RuntimeException();
1718
} finally {
19+
for (int i = 0; i &lt; 10; i ++) {
20+
//...
21+
if (q == i) {
22+
break; // ignored
23+
}
24+
}
25+
1826
/* ... */
1927
return; // Noncompliant - prevents the RuntimeException from being propagated
2028
}
@@ -36,12 +44,21 @@ <h2>Compliant Solution</h2>
3644
try {
3745
throw new RuntimeException();
3846
} finally {
47+
for (int i = 0; i &lt; 10; i ++) {
48+
//...
49+
if (q == i) {
50+
break; // ignored
51+
}
52+
}
53+
3954
/* ... */
4055
}
4156
}
4257
</pre>
43-
<h2>See</h2>
4458

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

0 commit comments

Comments
 (0)