S3626: FP in catch block ("Remove this redundant jump")

Hi,

there is a false-positive of squid:S3626:

A try-catch-finally with a return statement in the catch block and additional code after the finally-block.
The return is not redundant, because removing it leads to execution of the additional code, which is not supposed to be executed if an exception is caught.

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.");
}

using SonarLint 4.3.0.3495

possibly related to SONARJAVA-3058

Apparently there was a similar issue in SonarC#: https://github.com/SonarSource/sonar-dotnet/issues/1265

Hello @bduderstadt,

possibly related to SONARJAVA-3058

Good catch, it seems that it’s indeed related to this problem, I added your example to the ticket, thank you very much for the clean reproducer, it will help to better understand the problem.

Best,
Quentin

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.