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

Sergey Bylokhov serb at openjdk.java.net
Thu Nov 18 05:41:41 UTC 2021


On Wed, 13 Oct 2021 07:35:16 GMT, Andrey Turbanov <duke at openjdk.java.net> wrote:

>> 8274893: Update java.desktop classes to use try-with-resources
>
> 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?

src/java.desktop/share/classes/javax/swing/text/html/HTMLEditorKit.java line 463:

> 461:                         new InputStreamReader(is, ISO_8859_1));
> 462:                 defaultStyles.loadRules(r, null);
> 463:                 r.close();

the reader was not added to the try block, it will not be closed.

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.

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

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



More information about the client-libs-dev mailing list