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

CFG SE : nested statements in try catch end up with wrong CFG

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 3.10
    • Fix Version/s: 3.12
    • Component/s: CFG, Symbolic Execution
    • Labels:
      None

      Description

      In the following piece of code the catch blocks predecessor ends up wrong.

      void fun(boolean abort) {
      while (!abort) {
            try {
              synchronized (monitor) {
                long delay = 1000L;
                while (!shutdown && delay > 0) {
                  long now = System.currentTimeMillis();
                  monitor.wait(delay);
                  delay -= (System.currentTimeMillis() - now);
                }
                if (shutdown) {
                  abort = true;
                }
                doSomething(); // may throw an exception
              }
      
            } catch (RuntimeException e) {
              if (abort) { // <------------------------------------- S2583: Change this condition so that it does not always evaluate to "false"
                System.out.println("Abort");
              } else {
                System.out.println("Retry");
              }
            } catch (InterruptedException e) {
              Thread.currentThread().interrupt();
            }
      }
      

      This leads to wrong issues in SE because the paths are wrong.

      Problem seems to come from the fact that catches blocks are not hooked up to the last statement of the try block.

        Attachments

          Activity

            People

            • Assignee:
              didier.besset Didier Besset (Inactive)
              Reporter:
              nicolas.peru Nicolas Peru
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Due:
                Created:
                Updated:
                Resolved: