When a catch block contains code outside of the if statement performing the instanceof check, refactoring the code as the compliant example suggests would result in duplicating the same code. It is not cleaner, we should not report an issue.
Note that we should make sure to not miss real issues, such as:
But still, if the condition of the if is not a single instanceof, it makes sense to not report an issue, for example:
One strategy could be to report an issue only if:
- The catch block contains only if statements, return and thow.
- All the conditions of the if statements are single instanceof binary expressions.