mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 06:45:07 +02:00
8232003: (fs) Files.write can leak file descriptor in the exception case
Be sure to close the leaked OutputStream in all cases Reviewed-by: alanb, bpb, clanger
This commit is contained in:
parent
6fe51396a2
commit
dcc9cc3fdd
1 changed files with 2 additions and 2 deletions
|
@ -3550,8 +3550,8 @@ public final class Files {
|
|||
// ensure lines is not null before opening file
|
||||
Objects.requireNonNull(lines);
|
||||
CharsetEncoder encoder = cs.newEncoder();
|
||||
OutputStream out = newOutputStream(path, options);
|
||||
try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(out, encoder))) {
|
||||
try (OutputStream out = newOutputStream(path, options);
|
||||
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(out, encoder))) {
|
||||
for (CharSequence line: lines) {
|
||||
writer.append(line);
|
||||
writer.newLine();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue