Synchronization on 'this'
Reports synchronization on
class expressions. The reported constructs include
synchronized blocks and calls to
There are several reasons synchronization on
class expressions may be a bad idea:
it makes synchronization a part of the external interface of the class, which makes a future change to a different locking mechanism difficult,
it becomes hard to track just who is locking on a given object,
it makes a denial-of-service attack possible, either on purpose or it can happen easily by accident when subclassing.
As an alternative, consider synchronizing on a
private final lock object, access to which can be completely controlled.
IntelliJ IDEA 2023.3, Qodana for JVM 2023.3