S1166 ignores whitelist on multi-catch

Hi, the rule S1166: Exception handlers should preserve the original exceptions ignores the configured whitelist if a multi catch clause is used instead of individual catch clauses.

public class S1166_MultiCatch {

  public void method1() {
    try {
      exec();
    } catch (NumberFormatException e) {
      System.out.println("error");
    } catch (DateTimeParseException e) {
      System.out.println("error");
    }
  }

  public void method2() {
    try {
      exec();
    } catch (NumberFormatException | DateTimeParseException e) {
          // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
          // Either log or rethrow this exception
      System.out.println("error");
    }
  }


  private void exec() throws DateTimeParseException, NumberFormatException {

  }
}

The FP appears in both, SonarLint and SonarQube.

SonarLint version: 5.9
SonarQube version: 8.9.0 LTS

Oliver

Hello @oliver

I confirm what you observed and agree that this is a false positive. Ticket created: SONARJAVA-4041.

Thanks for the clear reproducer.

Best,
Quentin

1 Like

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