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
@ -3550,8 +3550,8 @@ public final class Files {
|
|||||||
// ensure lines is not null before opening file
|
// ensure lines is not null before opening file
|
||||||
Objects.requireNonNull(lines);
|
Objects.requireNonNull(lines);
|
||||||
CharsetEncoder encoder = cs.newEncoder();
|
CharsetEncoder encoder = cs.newEncoder();
|
||||||
OutputStream out = newOutputStream(path, options);
|
try (OutputStream out = newOutputStream(path, options);
|
||||||
try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(out, encoder))) {
|
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(out, encoder))) {
|
||||||
for (CharSequence line: lines) {
|
for (CharSequence line: lines) {
|
||||||
writer.append(line);
|
writer.append(line);
|
||||||
writer.newLine();
|
writer.newLine();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user