A return
statement in a finally block makes the control flow hard to understand; if the statement returns with a value, the try statement will always return with this value, ignoring a previous return value.
Solution: remove the return statement.
Severity level: 1
A throw
statement in a finally block makes the control flow hard to understand. It will mask an exception or a successful return from the try block, and make appear business code fail when simply the cleanup code failed.
Solution: refactor the exception handling in the try block
Severity level: 1
Empty catch blocks supposed to handle checked exceptions that are not expected to ever happen should handle this case in a more robust way.
Solution: add a Runtime exception to the catch block (e.g. throw new IllegalStateException();
, or use assert false;
.
Severity level: 2
Errors shouldn't be caught by user code without rethrowing, as recommended by Sun; they indicate a severe problem that can't be handled by user code, e.g. out of memory.
Solution: Revisit exception handling, and
Severity level: 2
Switch statements without a default branch will become a liability once the value range is expanded.
Solution: add a default branch that throws a runtime exception, such as java.lang.IllegalStateException, or use assert false;
Severity level: 3
Case statements fall through if not terminated by a return, break or a throw statement, as explained in section 4.11 of the JLS. This often occurs because of a forgotten break
statement.
Solution: add a control statement, if necessary
Severity level: 3