<i18n dev> RFR: 8274893: Update java.desktop classes to use try-with-resources [v2]

Andrey Turbanov duke at openjdk.java.net
Thu Nov 18 18:36:20 UTC 2021


On Thu, 18 Nov 2021 05:30:59 GMT, Sergey Bylokhov <serb at openjdk.org> wrote:

>> Andrey Turbanov has updated the pull request incrementally with two additional commits since the last revision:
>> 
>>  - 8274893: Update java.desktop classes to use try-with-resources
>>    close nested resources too
>>  - [PATCH] Use try-with-resources to close resources in java.desktop
>
> src/java.desktop/share/classes/com/sun/media/sound/StandardMidiFileReader.java line 150:
> 
>> 148:     public MidiFileFormat getMidiFileFormat(URL url) throws InvalidMidiDataException, IOException {
>> 149:         try (InputStream urlStream = url.openStream()) { // throws IOException
>> 150:             BufferedInputStream bis = new BufferedInputStream(urlStream, bisBufferSize);
> 
> Do we need to close the bis here and below as well?

I'm not sure it's 100% needed to close BufferedInputStream/BufferedReader wrappers. It's more code style question. Updated.

> src/java.desktop/share/classes/sun/print/PSPrinterJob.java line 398:
> 
>> 396:                 Properties props = new Properties();
>> 397:                 try (var is = new FileInputStream(f.getPath());
>> 398:                      var bis = new BufferedInputStream(is))
> 
> It will be better to use the same pattern everywhere, since the types are used in other places it will be good to use it here as well.

as you wish

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

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


More information about the i18n-dev mailing list