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

Don't consider nested lambda as within a synchronized block in S2273, S2276 and S2444

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 5.14
    • Component/s: Rules
    • Labels:
      None

      Description

      4 rules are today using the same (shared) approach to detect synchronized blocks, and will be impacted by the change:

      • S2276 (ThreadSleepCheck); FP removed when tread.sleep call is nested in a lambda:
         public synchronized Consumer<Object> get() {
          return s -> {
            Thread.sleep(200);    // Compliant, it was a FP!
          };
        }
      
      • S2273 (WaitInSynchronizeCheck): new issues:
         synchronized Consumer<String> foo3() {
          wait(); // Compliant
          return s -> {
            wait(); // Noncompliant, new issue, the call to wait is not inside a synchronized method.
          };
        }
      
      • S2444 (StaticFieldInitializationCheck): New issues
        static class E {
          static Config CONFIG;
      	
          synchronized static Consumer<String> bar() {
            return s -> {
              CONFIG = null; // Noncompliant, new issue, config is updated from a non-static method
            };
          }
        }
      
      • S2696 (StaticFieldUpateCheck): No changes, the implementation of the rule check if any parent is synchronized, not the direct one!

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                quentin.jaquier Quentin Jaquier
                Reporter:
                nicolas.peru Nicolas Peru
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Due:
                  Created:
                  Updated:
                  Resolved: