Inspectopedia
 
2024.3

Method with single 'synchronized' block can be replaced with 'synchronized' method

Warning
New
Last modified: 03 December 2024

Reports methods whose body contains a single synchronized statement. A lock expression for this synchronized statement must be equal to this for instance methods or [ClassName].class for static methods.

To improve readability of such methods, you can remove the synchronized wrapper and mark the method as synchronized.

Example:

After the quick-fix is applied: