提交 91fedda0 编写于 作者: S sgehwolf

8232003: (fs) Files.write can leak file descriptor in the exception case

Summary: Be sure to close the leaked OutputStream in all cases
Reviewed-by: alanb, bpb, clanger
上级 0ce54d50
......@@ -3348,8 +3348,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();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册