The implementaion of the sonar rule already allows exceptions for common patterns e.g. for NumberFormatException etc.
I suggest that allowing a similar handling for all unnamed variables would be consistent with the development of Java and giving the developer the freedom how to handle exceptions at their own discression.
Thank you for the suggestion! As Java evolves, we update our rules accordingly, but occasionally some are overlooked. I’ve created a ticket, SONARJAVA-6095 based on your report. The team will discuss it and decide on the next steps for implementation.
I am documenting the use of unnamed variables in S1166 and adding a reference to S7467 to the rule description in a PR, which may not be publicly visible.
Regarding the second implementation, I missed your contribution and implemented the change myself. Internal PRs are easier to merge because they do not require additional legal processes. Since you mentioned that this is fine with you, I will proceed with my implementation.
Your implementation is most likely wrong or at least not what you – or the language team –intended for this rule.
Your implementation does not catch the non-compliant inner catch (and your code lacks this test) in the below example. This is already the case for the existing excluded trivial cases where this might be ok to stop checking for further cases, but it is most likely not generally correct or the intention of this rule to omit further tests.
As I said I signed the contributor agreement, so do with my implementation and especially my tests (and me commit message explaning this) what you want.
The current impl might come back as an error issue.