Hi Andy,

A code like this is not safe
  try (Writer w = new BufferedWriter(new FileWriter( ...

because new BufferedWriter may throw an OutOfMemoryError, in that case the file 
descriptor used by the FileWriter is not freed.

There are two ways to fix that, either you need to expand the 
try-with-resources to use two lines
  try (FileWriter fileWriter = new FileWriter( ...);
       Writer w = new BufferedWriter(fileWriter)) { ...

or
  you use Files.newBufferedWriter(Path) which abstract the creation of a 
FileWriter and a BufferedWriter into one method,
  but you have to use a java.nio.file.Path instead a java.nio.File.

regards,
Rémi 

----- Mail original -----
> De: "Andy Herrick" <andy.herr...@oracle.com>
> À: "core-libs-dev" <core-libs-dev@openjdk.java.net>
> Envoyé: Jeudi 6 Juin 2019 01:54:05
> Objet: RFR: JDK-8223333: Use try-with-resources where feasible

> Please review the jpackage fix for bug [1] at [2].
> 
> This is a fix for the JDK-8200758-branch branch of the open sandbox
> repository (jpackage).
> 
> [1] https://bugs.openjdk.java.net/browse/JDK-8223333
> [2] http://cr.openjdk.java.net/~herrick/8223333/
> 
> /Andy

Reply via email to