Inspectopedia
 
2024.3

Convert try / finally to use() call

Info
New
Last modified: 03 December 2024

Reports a try-finally block with resource.close() in finally which can be converted to a resource.use() call.

use() is easier to read and less error-prone as there is no need in explicit close() call.

Example:

After the quick-fix applied: