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

FP on S128 (Switch cases without break) with nested switches

    Details

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

      Description

      In the following code, we raise a FP issue on the "BAR" case, but there is no need for a break statement, as all the cases of the nested switch are covered.

      class A {
        public enum E {
          A, B
        }
      
        public int test(String s, E e) {
          switch (s) {
            case "FOO":
              return 0;
            case "BAR": // FP - End this switch case with an unconditional break, return or throw statement.
              switch (e) {
                case A:
                  return 1;
                case B:
                  return 2;
                default:
                  throw new IllegalArgumentException();
              }
            default:
              throw new IllegalArgumentException();
          }
        }
      }
      

        Attachments

          Activity

            People

            • Assignee:
              christophe.zurn Christophe Zurn
              Reporter:
              michael.gumowski Michael Gumowski
            • Votes:
              1 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Due:
                Created:
                Updated:
                Resolved: