Empty Finally Block

ID

java.empty_finally_block

Severity

info

Remediation Complexity

auto_fix

Remediation Risk

low

Remediation Effort

low

Resource

Reliability

Language

Java

Tags

CWE:1071, reliability

Description

Reports finally blocks whose body is empty.

Rationale

An empty finally block is dead code. The finally clause exists to guarantee that cleanup runs regardless of whether an exception was thrown. An empty one adds visual noise and usually indicates that a resource release or cleanup step was intended but never implemented.

// Bad — empty finally
try {
    conn = openConnection();
    process(conn);
} finally {
}

Remediation

Either add the missing cleanup logic or remove the empty finally clause:

// Good — cleanup in finally
try {
    conn = openConnection();
    process(conn);
} finally {
    conn.close();
}