Method with single 'synchronized' block can be replaced with 'synchronized' method
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:
public int generateInt(int x) {
synchronized (this) {
return 1;
}
}
After the quick-fix is applied:
public synchronized int generateInt(int x) {
return 1;
}
Inspection Details | |
---|---|
Available in: | IntelliJ IDEA 2023.3, Qodana for JVM 2023.3 |
Plugin: | Java, 233.SNAPSHOT |
Last modified: 13 July 2023