GuardedBy and volatile
- Dominant language
- Java
- Stars
- 7.2k
- Forks
- 820
- Avg merge
- 5h 9m
- Merged PRs (30d)
- 50
Description
I guess this is more a question than an issue, but it needs clarification at least.
In our project we have several instances of a pattern where we have a field annotated with `@GuardedBy`, that field is `volatile` *and* we exploit that last fact to optimize reads.
It is used in places where the object referred by this field is not mutable (or at least not mutated), but the value of the reference may change. The updates are (usually) `synchronized` on the lock declared by `@GuardedBy`, but most reads just rely on the fact that the field is `volatile` and they do not need to acquire the lock.
This is where Error Prone comes in, as it flags those volatile reads.
The question is: is this correct?
And the supposition is: this should be allowed.
Please advise.
Contributor guide
Assessment
This issue has not been assessed yet.