When @Overrides
of synchronized
methods are not themselves synchronized
, the result can be improper
synchronization as callers rely on the thread-safety promised by the parent class.
Noncompliant code example
public class Parent {
synchronized void foo() {
//...
}
}
public class Child extends Parent {
@Override
public void foo () { // Noncompliant
// ...
super.foo();
}
}
Compliant solution
public class Parent {
synchronized void foo() {
//...
}
}
public class Child extends Parent {
@Override
synchronized void foo () {
// ...
super.foo();
}
}