[jdk8u-dev] RFR: 8274893: Update java.desktop classes to use try-with-resources

Timofei Pushkin tpushkin at openjdk.org
Mon Sep 1 11:02:50 UTC 2025


On Mon, 1 Sep 2025 10:40:38 GMT, Andrey Turbanov <aturbanov at openjdk.org> wrote:

>> Backport of [JDK-8274893](https://bugs.openjdk.org/browse/JDK-8274893) for parity with Oracle's JDK 8u461.
>> 
>> The first commit is a cherry-pick of the backport to JDK 11 with conflicts unresolved, the second resolves the conflicts, the rest resolve issues uncaught by git.
>> 
>> Resolved:
>> - `jdk/src/share/classes/com/sun/java/swing/plaf/gtk/Metacity.java`
>>   - Missing JDK-8271456: `"ISO-8859-1"` string is used instead of `ISO_8859_1` enum constant
>>   - Missing JDK-8041679: `StringBuffer` is used instead of `StringBuilder`
>> - `jdk/src/share/classes/javax/swing/text/html/HTMLEditorKit.java`
>>   - Missing JDK-8271456: `"ISO-8859-1"` string is used instead of `ISO_8859_1` enum constant
>> - `jdk/src/share/classes/com/sun/media/sound/StandardMidiFileWriter.java`
>>   - Missing JDK-8143909: no `Objects.requireNonNull(...)` in this version
>> - `jdk/src/solaris/classes/sun/awt/motif/MFontConfiguration.java`
>>   - Missing JDK-8054834: imports from `sun.font` package are still needed in this file
>> - `jdk/src/share/classes/com/sun/imageio/plugins/png/PNGImageReader.java`
>>   - Missing JDK-8080835: use `IOUtils.readAllBytes(InputStream is)` instead of the missing `InputStream.readAllBytes()`
>> - Missing JDK-7196163: try-with-resources cannot be used with pre-existing variables — fell back to try-finally in such cases
>> 
>> Testing: GitHub CI, `jdk_imageio` test group locally (headless linux/arm64)
>
> jdk/src/share/classes/com/sun/media/sound/JARSoundbankReader.java line 91:
> 
>> 89:         if (stream == null)
>> 90:             return null;
>> 91:         try {
> 
> There should be try-with-resources

There was in the original change but in this JDK try-with-resources on an existing variable is not possible (no JDK-7196163), so I fell back to try-finally. This is not the only place where I've done this, see [832c3c3](https://github.com/openjdk/jdk8u-dev/pull/686/commits/832c3c3bb4c132b025e7d3043b40be0d2d025a95).

Alternatives are to either create a copy variable for try-with-resources (which also must be used inside it to prevent a compiler warning) or move all interactions with the variable inside try-with-resources — both diverge code from the original change and the pre-existing code so I decided against them.

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

PR Review Comment: https://git.openjdk.org/jdk8u-dev/pull/686#discussion_r2313639165


More information about the jdk8u-dev mailing list