...
| Code Block | ||
|---|---|---|
| ||
class TryFinally {
private static boolean doLogic() {
try {
throw new IllegalStateException();
}
finally {
System.out.println(""Uncaught Exception"");
return true;
}
}
public static void main(String[] args) {
doLogic();
}
}
|
...
| Code Block | ||
|---|---|---|
| ||
class TryFinally {
private static boolean doLogic() {
try {
throw new IllegalStateException();
}
finally {
System.out.println(""Caught Exception"");
}
// any return statements must go here
}
public static void main(String[] args) {
doLogic();
}
}
|
...
Search for vulnerabilities resulting from the violation of this rule on the CERT website.
References
| Wiki Markup |
|---|
\[[JLS 05|AA. Java References#JLS 05]\] [Section 14.20.2, Execution of try-catch-finally|http://java.sun.com/docs/books/jls/third_edition/html/statements.html#14.20.2] \[[Bloch 05|AA. Java References#Bloch 05]\] Puzzle 36: Indecision \[[Chess 07|AA. Java References#Chess 07]\] 8.2 Managing Exceptions, ""The Vanishing Exception"" \[[MITRE 09|AA. Java References#MITRE 09]\] [CWE ID 705|http://cwe.mitre.org/data/definitions/705.html] ""Incorrect Control Flow Scoping"", [CWE ID 584|http://cwe.mitre.org/data/definitions/584.html] ""Return Inside Finally Block"" |
...
EXC07-J. Restore prior object state on method failure 13. Exceptional Behavior (EXC) EXC31-J. Handle checked exceptions that can be thrown within a finally block