RFR: 8155591: Misleading warning when not overriding close method in interface extending AutoCloseable [v2]

Pavel Rappo prappo at openjdk.org
Wed Nov 5 16:05:45 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?
> 
> ```java
> 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.

Good catch! WithClose.close() does override AutoCloseable.close() from Try.

-------------

PR Comment: https://git.openjdk.org/jdk/pull/27062#issuecomment-3492055450


More information about the compiler-dev mailing list