RFR: 8155591: Misleading warning when not overriding close method in interface extending AutoCloseable [v2]
Archie Cobbs
acobbs at openjdk.org
Wed Nov 5 21:19:03 UTC 2025
On Tue, 4 Nov 2025 10:56:24 GMT, Jan Lahoda <jlahoda at openjdk.org> wrote:
> Makes sense to me. I think it would be useful if the tests would be enhanced to cover the case where the `close` method declaration in non-AutoClo does actually `Exception`/`InterruptedException`. I found `InterruptedExceptionTest.java`, but as that's a combo test, it is harder to see a sensible warning is produced on a sensible place.
Good idea - added in d9b78c60242.
> Regarding sensible place, it would be possible to produce a warning specifically at the problematic `close` method (if it is declared in the given class, and not inherited) using `TreeInfo.diagnosticPositionFor`, but it is not so easy in this case - among other things, the warning would probably need a different wording. Up to you.
I agree that would be better: if a declaration is what's causing the warning to be generated, then the warning should be located at that declaration.
Since you already approved this PR, I've implemented that last idea in an [alternate branch](https://github.com/archiecobbs/jdk/compare/JDK-8155591...archiecobbs:jdk:JDK-8155591-alt1). Take a look and let me know if you prefer that, or want to stick with what's already approved.
Thanks!
-------------
PR Comment: https://git.openjdk.org/jdk/pull/27062#issuecomment-3493506216
More information about the compiler-dev
mailing list