Empty Synchronized Block

ID

java.empty_synchronized_block

Severity

low

Remediation Complexity

trivial

Remediation Risk

low

Remediation Effort

low

Resource

Reliability

Language

Java

Tags

CWE:1071, concurrency, reliability

Description

Reports synchronized blocks whose body is empty.

Rationale

An empty synchronized block acquires a monitor, does nothing, and releases it. This wastes CPU cycles, can cause unnecessary thread contention, and misleads readers into thinking the section protects some shared state. It usually indicates incomplete refactoring or a placeholder that was never filled in.

// Bad -- empty synchronized block
synchronized (lock) {
}

Remediation

Add the intended thread-safe logic or remove the empty block:

// Good -- synchronized block with content
synchronized (lock) {
    sharedCounter++;
}