Find unclosed custom resources

Proprietary

Finds resources of a kind the options describe that a method opens in a local variable and does not close on every path, nor return, pass to another method or store in a field. A resource is opened by a constructor or a factory method, or by an opening method called on it, and closed by the closing method. This covers resources that do not implement AutoCloseable, which FindUnclosedResources covers, with the same analysis: a close in a finally block that a return runs, under a null check, through another variable, or in every case of a switch is not followed. Test sources are not searched.

org.openrewrite.analysis.java.dataflow.FindUnclosedCustomResources

Required

A method pattern matching the methods that close the resource they are called on.

Optional

A method pattern matching the constructors that create an open resource.

A method pattern matching the methods that return an open resource.

A method pattern matching the methods that open the resource they are called on.

mod run . --recipe=org.openrewrite.analysis.java.dataflow.FindUnclosedCustomResources \ -P closingMethodPattern='com.acme.Connection release()'

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