Inspectopedia Help

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

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:

PrintStream printStream = new PrintStream(fileName); try { printStream.print(true); } finally { printStream.close(); }

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

try (PrintStream printStream = new PrintStream(fileName)) { printStream.print(true); }

This inspection only reports if the language level of the project or module is 7 or higher.

Inspection Details

Available in:

IntelliJ IDEA 2023.3, Qodana for JVM 2023.3

Plugin:

Java, 233.SNAPSHOT

Last modified: 13 July 2023