The rule S1193 intends to avoid Exception handling branching through instanceof tests. That’s great. Unfortunately, this rule produces false-positives only here, as we never do THIS:
catch ( Exception e )
{
if ( e instanceof MyException1 )
doSomething1();
else if ( e instanceof MyException2 )
doSomething2();
else if ( e instanceof MyException3 )
doSomething3();
}
But it produces false positives here. But the code is correct and cannot really be altered to please this rule.
catch ( MyException e )
{
// Do non trivial exception handling.
if ( e instanceof MySpecialExcetion ) // FP
doSomethingSpecialAdditionally();
// Do more non trivial exception handling.
}
So, if the instanceof test is prepended or followed by actualy code, the rule should not hit.
What do you think? The rule’s goal to avoid the above (first) kind of handling, is a good one. But the second block shows actual handling from real cases, that are not too uncommon, I suppose.