Remove catch clauses hidden by earlier ones

Proprietary

Removes a catch clause for a checked exception, or one type of a multi-catch, when every exception the try block can throw that it would catch is already caught by a clause above it. Such a clause compiles, but never runs. What the try block can throw is read from the throws clauses of the methods and constructors it calls, the throw statements it holds and the close() methods of its resources, with a method marked @SneakyThrows taken to throw anything. A try block with a call or a type that cannot be resolved or a Lombok @Cleanup variable is left alone, as are test sources. A clause is left alone when the code after the try statement could become unreachable without it, when it breaks out of a loop or switch, when it returns from a lambda, when it can throw a checked exception inside another try or a lambda or when it assigns the exception of an enclosing catch, and a multi-catch type when the clause reads its exception.

io.moderne.staticanalysis.RemoveHiddenCatchClause
mod run . --recipe=io.moderne.staticanalysis.RemoveHiddenCatchClause

Install it once from Recipe actions, then run it on every repository under the current directory. New to the Moderne CLI? Set it up.