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