Incorrect "AutoCloseable used without 'try'-with-resources" warning for append call?

Answered

Incorrect "AutoCloseable used without 'try'-with-resources" warning for append call for following code? (IU-143.2287, Intellij IDEA Ultimate 15.0.4 (lame you can't copy this from the About screen too), JDK 8 on OS X Mavericks 10.9.5).

static void foo() throws IOException {
try(BufferedWriter wr = new BufferedWriter(new FileWriter("foo.txt"))) {
wr.append("bar"); // <- produces warning
}
}
0
11 comments

Just noticed if i check "Ignore AutoCloseable instances returned from method calls" it goes away, but it still seems spurious to me when that's unchecked.

0

> lame you can't copy this from the About screen too

Actually, you can: https://youtrack.jetbrains.com/issue/IDEA-70737.

0

I'll be damned - thank you; it's not at all clear UI-wise.

0

Would be cool if you could just select the text; that applies elsewhere too like in the preferences menu when i want to copy the preference name for a bug report.

0

Selecting text in About dialog is not an easy task to implement, see https://youtrack.jetbrains.com/issue/IDEA-152558 why. IDEA 16 already displays a hint that you can copy the info from About dialog.

0

I sympathize with reporter's (https://youtrack.jetbrains.com/issue/IDEA-152558 ) desire to copy as much text as possible but am by no means a UI expert or product manager and appreciate the complexity - value tradeoffs - thanks for the feedback!

Any ideas on my real question would be cool :)

0

> Any ideas on my real question would be cool :)

I've asked the responsible developer to have a look.

0

awesome - thanks Serge!

0

This has come back (or it never went away). I see it in IDEA 2022.1.3 (Ultimate Edition), Build #IU-221.5921.22, built on June 21, 2022.

As a work-around, I have enabled "Ignore AutoCloseable instances returned from method calls" checkbox in the inspection's settings (File -> Settings -> Editor -> Inspections -> Java -> Resource Management -> AutoCloseable ...).

0

Craig Larsen the issue is not reproduced for me with the sample code posted above in 2022.1.3 and 2022.2 EAP 7. Could you please share your code sample?

0

Please sign in to leave a comment.