8209386: [error-prone] StreamResourceLeak in jdk.internal.ed module
Reviewed-by: rriggs
--- a/src/jdk.internal.ed/share/classes/jdk/internal/editor/external/ExternalEditor.java Wed Sep 05 13:10:40 2018 -0700
+++ b/src/jdk.internal.ed/share/classes/jdk/internal/editor/external/ExternalEditor.java Fri Aug 10 13:36:10 2018 -0700
@@ -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.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 @@
}
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());
}