Synchronizing on non-final fields is not safe: if the field is ever updated, different threads may end up locking on different objects.
- If the field is already effectively final, add the missing ‘final’ modifier.
- If the field needs to be mutable, create a separate lock by adding a private final field and synchronizing on it to guard all accesses.
Suppress false positives by adding an
@SuppressWarnings("SynchronizeOnNonFinalField") annotation to the enclosing element.