8209386: [error-prone] StreamResourceLeak in jdk.internal.ed module

Reviewed-by: rriggs
This commit is contained in:
Igor Ignatyev 2018-08-10 13:36:10 -07:00
parent e51b1f0cf6
commit be5de9ef3b

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -40,6 +40,7 @@ import java.util.Arrays;
import java.util.Scanner;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import static java.nio.file.StandardWatchEventKinds.ENTRY_CREATE;
import static java.nio.file.StandardWatchEventKinds.ENTRY_DELETE;
import static java.nio.file.StandardWatchEventKinds.ENTRY_MODIFY;
@ -188,8 +189,8 @@ public class ExternalEditor {
}
private void saveFile() {
try {
saveHandler.accept(Files.lines(tmpfile).collect(Collectors.joining("\n", "", "\n")));
try (Stream<String> lines = Files.lines(tmpfile)) {
saveHandler.accept(lines.collect(Collectors.joining("\n", "", "\n")));
} catch (IOException ex) {
errorHandler.accept("Failure in read edit file: " + ex.getMessage());
}