Uploaded image for project: 'SonarJava'
  1. SonarJava
  2. SONARJAVA-2379

FP on S2222 when call to unlock() is caught by parent try-catch-finally

    Details

    • Type: False-Positive
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: Rules, Symbolic Execution
    • Labels:
      None

      Description

      Rule S2222 (Locks should be released) is raising a FP when call to unlock() is present in nested try-catch blocks.
      In such situations, the SE engine assume that unlock() (like any other methods) can throw a runtime exception, and consequently branch to any possible catch from parent try-catch, with the state of the lock still considered LOCKED.

      abstract class A {
        public void foo(java.util.concurrent.locks.Lock w) {
          try {
            w.lock(); // FP on w, which is necessarily unlocked in the finally.
            try {
              doSomething();
            } finally {
              w.unlock();
            }
          } catch (Exception e) {
            doSomething();
          }
        }
      
        abstract void doSomething();
      }
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                michael.gumowski Michael Gumowski
              • Votes:
                1 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated: