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

CFG not build correctly when combining break/continue and try-finally

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 4.14
    • Fix Version/s: 5.1.1
    • Component/s: CFG
    • Labels:
      None

      Description

      In all the following methods, the CFG which is build is wrong. The break or continue statement within the body of the try should lead to the first element of the finally block, but it systematically lead to only the last statement: System.out.println(...). This leads to wrong state in the stack of the generated program states, which are then unable to unstack the correct amount of elements.

      class InterruptedLoop {
        void run1() {
          while (true) {
            try {
              break;
            } finally {
              String s = true ? "" : "";
              System.out.println(s);
            }
          }
        }
      
        void run2() {
          while (true) {
            try {
              continue;
            } finally {
              System.out.println(true ? "" : "");
            }
          }
        }
      
        void run3() {
          for (int i = 0; i < 5; i++) {
            try {
              break;
            } finally {
              String s;
              System.out.println(true ? "" : "");
            }
          }
        }
      
        void run4() {
          while (true) {
            try {
              break;
            } finally {
              String s;
              if (true) { s = ""; } else { s = ""; }
              System.out.println(s);
            }
          }
        }
      }
      

      When looking at the graph, B5 should lead to B4, but it systematically leads to B1 (method invocation), which is wrong.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                nicolas.peru Nicolas Peru
                Reporter:
                michael.gumowski Michael Gumowski
              • Votes:
                2 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Due:
                  Created:
                  Updated:
                  Resolved: