RFR: 8274881: Update jdk.compiler classes to use try-with-resources

Andrey Turbanov duke at openjdk.java.net
Tue Oct 12 08:14:57 UTC 2021


On Tue, 12 Oct 2021 02:52:43 GMT, Joe Darcy <darcy at openjdk.org> wrote:

>> 8274881: Update jdk.compiler classes to use try-with-resources
>
> src/jdk.compiler/share/classes/com/sun/tools/javac/util/ByteBuffer.java line 172:
> 
>> 170:                  * should be reported.
>> 171:                  */
>> 172:             }
> 
> The exception behavior seems like it could differ, which may or may not be an issue.

Yes. Behavior is changed for the case, when we read InputStream up the end _without_ any exception and then get Exception during _close_ call.
But I think it still worth changing:
1. Code is shorter and cleaner
2. Such case is very rare, when only `InputStream.close` throw exception, but `InputStream.read` did not
3. Swallowing exceptions, even during `close()` call, is a bad code smell.

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

PR: https://git.openjdk.java.net/jdk/pull/5816


More information about the compiler-dev mailing list