[java] A false positive about the rule THREAD_SAFETY_VIOLATION
- Dominant language
- OCaml
- Stars
- 15.7k
- Forks
- 2.1k
- Avg merge
- 19h 36m
- Merged PRs (30d)
- 13
Description
**Version**. `Infer version v1.1.0`
**OS**. `Ubuntu 22.04.3 LTS`
**Command**. `infer run -- mvn clean compile`
I found a false positive about the rule [THREAD_SAFETY_VIOLATION](https://fbinfer.com/docs/all-issue-types#thread_safety_violation).
According to the description of the rule, infer should not check the method annotated with `@VisibleForTesting`.
In the example below, however, infer report a `THREAD_SAFETY_VIOLATION` warning at line 16
```java
import javax.annotation.concurrent.ThreadSafe;
import android.support.annotation.VisibleForTesting;
@ThreadSafe
public class B {
boolean mField;
void writeUnderLockOk() {
synchronized (this) {
mField = true;
}
}
@VisibleForTesting
boolean readOutsideLock1Bad() {
synchronized (this) {}
return mField;
}
}
```
```bash
warning: Thread Safety Violation Read/Write race. Non-private method `B.readOutsideLock1Bad()` reads without synchronization from `this.mField`. Potentially races with write in method `B.writeUnderLockOk()`.
Reporting because the current class is annotated `@ThreadSafe`, so we assume that this method can run in parallel with other non-private methods in the class (including itself).
```
Hence, I think it is a fasle positive.
Contributor guide
Assessment
This issue has not been assessed yet.