changeset 3241:17d15aa9140d

8139961: Various sjavac tests result in error on Windows (JPRT) Summary: Test now closes Stream properly. Reviewed-by: jlahoda
author alundblad
date Wed, 04 Nov 2015 12:27:00 +0100
parents a32f899caa49
children 3298cbc00d2f
files test/tools/sjavac/NoState.java
diffstat 1 files changed, 10 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/test/tools/sjavac/NoState.java	Tue Nov 03 22:55:30 2015 +0100
+++ b/test/tools/sjavac/NoState.java	Wed Nov 04 12:27:00 2015 +0100
@@ -36,8 +36,9 @@
 
 import com.sun.tools.javac.util.Assert;
 
-import java.util.*;
+import java.io.IOException;
 import java.nio.file.*;
+import java.util.stream.Stream;
 
 public class NoState extends SJavacTester {
     public static void main(String... args) throws Exception {
@@ -57,7 +58,13 @@
         Assert.check(Files.exists(BIN.resolve("pkg/A.class")));
 
         // Make sure we have no other files (such as a javac_state file) in the bin directory
-        Assert.check(Files.list(BIN).count() == 1);
-        Assert.check(Files.list(BIN.resolve("pkg")).count() == 1);
+        Assert.check(countPathsInDir(BIN) == 1);
+        Assert.check(countPathsInDir(BIN.resolve("pkg")) == 1);
+    }
+
+    private long countPathsInDir(Path dir) throws IOException {
+        try (Stream<Path> files = Files.list(dir)) {
+            return files.count();
+        }
     }
 }