Inspectopedia
 
2024.3

'try finally' can be replaced with 'try' with resources

Warning
New
Last modified: 03 December 2024

Reports try-finally statements that can use Java 7 Automatic Resource Management, which is less error-prone.

A quick-fix is available to convert a try-finally statement into a try-with-resources statement.

Example:

A quick-fix is provided to pass the cause to a constructor:

This inspection depends on the Java feature 'Try-with-resources', which is available since Java 7.