[Java] Infer fails to detect a deadlock bug
- Dominant language
- OCaml
- Stars
- 15.7k
- Forks
- 2.1k
- Avg merge
- 19h 36m
- Merged PRs (30d)
- 13
Description
Hi, I found that Infer fails to detect a deadlock in the following code example. It should have reported a deadlock warning at lines 9 and 14, as these two methods acquire locks `this` and `lockB` in reverse order, which can lead to a deadlock. This constitutes a false negative in deadlock detection.
### Minimized Code Example
```java
import android.support.annotation.UiThread;
import android.support.annotation.WorkerThread;
public class Main {
private final Object lockB = new Object();
@UiThread
public synchronized void annotatedUiThreadBad() {
lockSync();
}
@WorkerThread
public void annotatedWorkerThreadBad() {
syncLocks(lockB, this);
}
private void lockSync() {
synchronized (lockB) {}
}
private void syncLocks(Object lock1, Object lock2) {
synchronized (lock1) { synchronized (lock2) {} }
}
}
```
### Analysis Log
```bash
Capturing in javac mode...
Found 1 source file to analyze in /infer-out
0/6 [................................................................................] 0% 126ms
⊢ [ 0.1s][17.8M] idle
⊢ [ 0.1s][17.8M] Main.java: Main.()
3/6 [########################################........................................] 50% 185ms
⊢ [ 0.0s][17.8M] void Main.annotatedUiThreadBad()
⊢ [ 0.1s][17.8M] idle
6/6 [################################################################################] 100% 191ms
⊢ [ 0.0s][17.8M] idle
⊢ [ 0.1s][17.8M] idle
⊢ [ 0.1s][17.8M] idle
No issues found
```
Contributor guide
Assessment
This issue has not been assessed yet.