< prev index next >

test/jdk/java/nio/file/FileSystem/Basic.java

Print this page

        

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 2008, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008, 2020, 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
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.

@@ -20,11 +20,11 @@
  * or visit www.oracle.com if you need additional information or have any
  * questions.
  */
 
 /* @test
- * @bug 4313887 6838333 8132497
+ * @bug 4313887 6838333 8132497 8242292
  * @summary Unit test for java.nio.file.FileSystem
  * @library .. /test/lib
  * @build jdk.test.lib.Platform
  *        jdk.test.lib.util.FileUtils
  * @run main/othervm Basic

@@ -89,10 +89,27 @@
             System.out.println("Expected ProviderNotFoundException caught: "
                 + "\"" + pnfe.getMessage() + "\"");
         }
     }
 
+    static void checkIAE() throws IOException, URISyntaxException {
+        String dir = System.getProperty("test.dir", ".");
+        String fileName = dir + File.separator + "foo.bar";
+        Path path = Path.of(dir, fileName);
+        URI uri = new URI(path.toString());
+        System.out.println(uri);
+        try {
+            FileSystem fs = FileSystems.getFileSystem(uri);
+            throw new RuntimeException("IllegalArgumentException expected");
+        } catch (IllegalArgumentException iae) {
+            System.out.println("Expected IllegalArgumentException caught: "
+                + "\"" + iae.getMessage() + "\"");
+        } catch (Exception e) {
+            throw new RuntimeException("IllegalArgumentException expected", e);
+        }
+    }
+
     public static void main(String[] args)
         throws IOException, URISyntaxException {
         String os = System.getProperty("os.name");
         FileSystem fs = FileSystems.getDefault();
 

@@ -120,10 +137,14 @@
         if (os.contains("OS X"))
             checkSupported(fs, "posix", "unix", "owner");
         if (os.equals("Windows"))
             checkSupported(fs, "owner", "dos", "acl", "user");
 
+        // sanity check throwing of IllegalArgumentException by
+        // FileSystems.getFileSystem(URI) if the URI scheme is null
+        checkIAE();
+
         // sanity check non-throwing of UnsupportedOperationException by
         // FileSystems.newFileSystem(URI, ..)
         checkNoUOE();
     }
 }
< prev index next >