Skip to content

False Positive : Non-double-checked pattern is reported as DoubleCheckedLocking #5668

@Carlson-JLQ

Description

@Carlson-JLQ

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions