Skip to content

[Java] Infer fails to detect a deadlock bug #1949

@RJerrica

Description

@RJerrica

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

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

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.<init>()
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  

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