RFR: 8155591: Misleading warning when not overriding close method in interface extending AutoCloseable [v2]
Archie Cobbs
acobbs at openjdk.org
Tue Nov 4 23:56:30 UTC 2025
On Tue, 4 Nov 2025 10:56:24 GMT, Jan Lahoda <jlahoda at openjdk.org> wrote:
>> Archie Cobbs has updated the pull request with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains two additional commits since the last revision:
>>
>> - Merge branch 'master' into JDK-8155591 to get recent build fixes.
>> - Don't warn about AutoCloseable.close() itself throwing InterruptedException.
>
> 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.
>
> 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.
Hi @lahodaj thanks for taking a look.
I just realized there is another potential issue. Shouldn't a warning also be generated in this example?
class WithClose {
public void close() throws Exception { }
}
public class Try extends WithClose implements AutoCloseable { }
Currently the compiler does not generate one; I'm not sure yet what exact logical tweak would be needed.
-------------
PR Comment: https://git.openjdk.org/jdk/pull/27062#issuecomment-3488465787
More information about the compiler-dev
mailing list