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

FP in S2222 when Lock is coming from another method

    Details

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

      Description

      The following pattern (proposed in the documentation) is correctly supported:

        private static void if_try_lock() {
          Lock lock = new ReentrantLock();
          if(lock.tryLock()) { // Compliant
            try {
      
            } finally {
              lock.unlock();
            }
          }
        }
      

      However, when the Lock is coming from an argument and the method is called (no issue if not called...), an issue is still raised.

        private static void calling_if_try_lock2() {
          if_try_lock2(new ReentrantLock());
        }
      
        private static void if_try_lock2(Lock lock) throws Exception {
          if (lock.tryLock()) {
            try {
      
            } finally {
              lock.unlock();
            }
          }
        }
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                quentin.jaquier Quentin Jaquier
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated: