Skip to content

@GuardedBy checks inconsistent: variables vs methods, 'this' qualifier, etc. #841

@goldberg-n

Description

@goldberg-n

(2.1.3)

I noticed a bunch of weirdness with @GuardedBy: mostly it works as expected, but in quite a few cases that Error Prone should complain, it doesn't.

Altering this test slightly:

class Test {
    final Object mu = new Object();
    @GuardedBy("mu") int y;
    @GuardedBy("mu") void y() {}
}

class Main {
    void m(Test t) {
        t.y++; // Barfs, as expected
        t.y(); // No complaints
    }
}

Some more oddities:

class Main {
    void m(Test t) {
        // ErrorProne complains, as expected
        thisLock();
        t.classLock();

        // ErrorProne is fine with these?
        this.thisLock();
        t.testLock();
    }

    @GuardedBy("this") void thisLock() {}
}
 
class Test {
    @GuardedBy("Test.class") void classLock () {}
    @GuardedBy("this") void testLock() {}
}

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