changeset 2683:eaf0d6b44ece

Ensure directory stream is closed when searching for .jimage files
author jjg
date Fri, 24 Oct 2014 14:48:08 -0700
parents 8dd333dfc21c
children f0cf1b34ee4b
files src/jdk.compiler/share/classes/com/sun/tools/javac/file/Locations.java
diffstat 1 files changed, 9 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/file/Locations.java	Tue Oct 21 11:53:29 2014 -0700
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/file/Locations.java	Fri Oct 24 14:48:08 2014 -0700
@@ -46,6 +46,7 @@
 import java.util.Set;
 import java.util.StringTokenizer;
 import java.util.stream.Collectors;
+import java.util.stream.Stream;
 import java.util.zip.ZipFile;
 
 import javax.tools.JavaFileManager;
@@ -699,12 +700,14 @@
             // Return .jimage files if available
             Path libModules = Paths.get(home, "lib", "modules");
             if (Files.exists(libModules)) {
-                Collection<File> images = Files.list(libModules)
-                        .filter(f -> f.getFileName().toString().endsWith(".jimage"))
-                        .map(Path::toFile)
-                        .collect(Collectors.toList());
-                if (!images.isEmpty())
-                    return images;
+                try (Stream<Path> files = Files.list(libModules)) {
+                    Collection<File> images = files
+                            .filter(f -> f.getFileName().toString().endsWith(".jimage"))
+                            .map(Path::toFile)
+                            .collect(Collectors.toList());
+                    if (!images.isEmpty())
+                        return images;
+                }
             }
 
             // Temporary: if no .jimage files, return individual modules