google / google/error-prone

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

Open
#841 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
7.2k
Forks
820
Avg merge
5h 9m
Merged PRs (30d)
50

Description

(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](https://github.com/google/error-prone/blob/88aa0bdc2b7f07e7aa7690aef0fdd75e2c7e180c/core/src/test/java/com/google/errorprone/bugpatterns/threadsafety/GuardedByCheckerTest.java#L270) 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() {}
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.