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

FP in S2201: support new switch expression

    XMLWordPrintable

    Details

    • Type: False-Positive
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 6.6
    • Component/s: Rules
    • Labels:
      None

      Description

      With new switch expression (Java 12), return values from functions without side effects are not ignored.

      String s = "";
      
      String v = switch (cond) {
       case "1" -> "aValue";
       case "2" -> s.toString(); // FP
       case "3" -> s.substring(1); // FP
       default -> s.replace('a', 'b'); // FP
      };
      

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              evgeny.mandrikov Evgeny Mandrikov
              Reporter:
              quentin.jaquier Quentin Jaquier
              Votes:
              1 Vote for this issue
              Watchers:
              3 Start watching this issue

                Dates

                Due:
                Created:
                Updated:
                Resolved: