-
Notifications
You must be signed in to change notification settings - Fork 787
False Negative : Unsynchronized overrides of synchronized methods are missed #5675
Copy link
Copy link
Open
Description
False Negative : Unsynchronized overrides of synchronized methods are missed
Affects errorprone Version:
2.48.0
Checker:
UnsynchronizedOverridesSynchronized
Description:
The official UnsynchronizedOverridesSynchronized checker warns when a subclass overrides a synchronized method with a method that is not synchronized. Both samples below match that description directly.
Code Sample demonstrating the issue:
// PosCase1
static class Parent {
synchronized void method() {}
}
static class Child extends Parent {
@Override
void method() {
// non-synchronized override
}
}
// Sonar PosCase1
static class Parent {
synchronized void synchronizedMethod() {
System.out.println("Parent synchronized method");
}
}
static class Child extends Parent {
@Override
void synchronizedMethod() {
System.out.println("Child non-synchronized override");
}
}In both cases, the subclass removes the synchronized modifier from an overridden method, which weakens the thread-safety contract promised by the parent type.
Expected outcome:
Error Prone should report these overrides under UnsynchronizedOverridesSynchronized, but it doesn't. This is a false-negative.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels