-
Notifications
You must be signed in to change notification settings - Fork 787
False Positive : Non-double-checked pattern is reported as DoubleCheckedLocking #5668
Copy link
Copy link
Closed
Description
False Positive : Non-double-checked pattern is reported as DoubleCheckedLocking
Affects errorprone Version:
2.48.0
Checker:
DoubleCheckedLocking
Description:
The official DoubleCheckedLocking bug pattern targets the classic lazy-initialization shape: an outer null check, a synchronized block, and an inner null check on the same non-volatile field. This test case does not follow that pattern because the outer condition is f != null, not f == null.
Code Sample demonstrating the issue:
public class NegCase2 {
private Object f;
public void method() {
if (f != null) {
synchronized (this) {
if (f == null) {
f = new Object();
}
}
}
}
}This code is inconsistent and suspicious in its own way, but it is not the canonical double-checked locking pattern described by Error Prone. The bug pattern documentation specifically talks about unsafe lazy initialization with repeated null checks on a non-volatile field.
Expected outcome:
Error Prone should not report DoubleCheckedLocking for this code, but it does. This is a false-positive.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels