Details

    • Type: False-Positive
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: CFG, Rules
    • Labels:
      None

      Description

      Implementation of RSPEC-3626 is based on CFG, and it raises a FP on the following (simplified) case:

      abstract class A {
      
        public void tst() {
          while (!foo()) {
            try {
              boomException();
            } catch (MyException e) {
              return; // FP - the return statement is NOT redundant, because without it we would restart the loop
            } finally {
              foo();
            }
          }
        }
      
        abstract boolean foo();
        abstract void boomException() throws MyException;
        public static class MyException extends Exception {  }
      
      }
      

      Note that the CFG is correct, from the block of the catch, the only way is through exit, and it does not come back to the loop.

      This comes from internal feedback.

       

      Two others cases from community : 

          void foo(boolean b) {
              try {
                  if (b) {
                      System.out.println("work block A");
                  } else {
                      return;
                  }
              } finally {
                  System.out.println("work block B");
              }
              System.out.println("work block C");
          } 
      void foo() {
        try {
          System.out.println("In try block.");
          doSomethingThatMightThrow();
        } catch (RuntimeException ex) {
          System.out.println("In catch block.");
          return; // squid:S3626 false positive here
        } finally {
          System.out.println("In finally block.");
        }
        System.out.println("This should only be printed if no exception occurred.");
      }
      

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              michael.gumowski Michael Gumowski
            • Votes:
              1 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated: