changeset 3801:07a2dfc18d68

8165564: langtools\test\jdk\jshell\CommandCompletionTest.java fails on some windows Summary: Ignoring non-existent default FileSystem roots. Reviewed-by: rfield
author jlahoda
date Mon, 05 Dec 2016 19:42:42 +0100
parents 7282b1bc25f2
children 8fc0a7bf47a9
files src/jdk.jshell/share/classes/jdk/internal/jshell/tool/JShellTool.java test/jdk/jshell/CommandCompletionTest.java
diffstat 2 files changed, 14 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/JShellTool.java	Fri Dec 02 14:15:43 2016 -0800
+++ b/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/JShellTool.java	Mon Dec 05 19:42:42 2016 +0100
@@ -1091,6 +1091,7 @@
             }
             if (path.isEmpty()) {
                 StreamSupport.stream(FileSystems.getDefault().getRootDirectories().spliterator(), false)
+                             .filter(root -> Files.exists(root))
                              .filter(root -> accept.test(root) && root.toString().startsWith(prefix))
                              .map(root -> new ArgSuggestion(root.toString()))
                              .forEach(result::add);
--- a/test/jdk/jshell/CommandCompletionTest.java	Fri Dec 02 14:15:43 2016 -0800
+++ b/test/jdk/jshell/CommandCompletionTest.java	Mon Dec 05 19:42:42 2016 +0100
@@ -46,6 +46,7 @@
 import java.util.function.Predicate;
 import java.util.stream.Collectors;
 import java.util.stream.Stream;
+import java.util.stream.StreamSupport;
 
 import org.testng.annotations.Test;
 
@@ -144,7 +145,7 @@
         Compiler compiler = new Compiler();
         assertCompletion("/o|", false, "/open ");
         List<String> p1 = listFiles(Paths.get(""));
-        FileSystems.getDefault().getRootDirectories().forEach(s -> p1.add(s.toString()));
+        getRootDirectories().forEach(s -> p1.add(s.toString()));
         Collections.sort(p1);
         assertCompletion("/open |", false, p1.toArray(new String[p1.size()]));
         Path classDir = compiler.getClassDir();
@@ -157,7 +158,7 @@
         assertCompletion("/s|", false, "/save ", "/set ");
         List<String> p1 = listFiles(Paths.get(""));
         Collections.addAll(p1, "-all ", "-history ", "-start ");
-        FileSystems.getDefault().getRootDirectories().forEach(s -> p1.add(s.toString()));
+        getRootDirectories().forEach(s -> p1.add(s.toString()));
         Collections.sort(p1);
         assertCompletion("/save |", false, p1.toArray(new String[p1.size()]));
         Path classDir = compiler.getClassDir();
@@ -198,7 +199,7 @@
 
     public void testSet() throws IOException {
         List<String> p1 = listFiles(Paths.get(""));
-        FileSystems.getDefault().getRootDirectories().forEach(s -> p1.add(s.toString()));
+        getRootDirectories().forEach(s -> p1.add(s.toString()));
         Collections.sort(p1);
 
         String[] modes = {"concise ", "normal ", "silent ", "verbose "};
@@ -267,4 +268,13 @@
                     (Files.isDirectory(file) ||
                      file.getFileName().toString().endsWith(".jar") ||
                      file.getFileName().toString().endsWith(".zip"));
+
+    private static Iterable<? extends Path> getRootDirectories() {
+        return StreamSupport.stream(FileSystems.getDefault()
+                                               .getRootDirectories()
+                                               .spliterator(),
+                                    false)
+                            .filter(p -> Files.exists(p))
+                            .collect(Collectors.toList());
+    }
 }