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

Print this page
rev 12500 : 8132497: (fs) FileSystems.newFileSystem(URI, ..) doesn't handle UOE thrown by provider
Summary: Handle UOEs in newFileSystem(URI,...) similarly to as done in newFileSystem(Path path, ClassLoader loader).
Reviewed-by: XXX

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 2008, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008, 2015, 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,21 +20,24 @@
  * or visit www.oracle.com if you need additional information or have any
  * questions.
  */
 
 /* @test
- * @bug 4313887 6838333
+ * @bug 4313887 6838333 8132497
  * @summary Unit test for java.nio.file.FileSystem
  * @library ..
  */
 
+import java.io.File;
 import java.nio.file.*;
-import java.nio.file.attribute.*;
 import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.HashMap;
 
 /**
- * Simple santity checks for java.nio.file.FileSystem
+ * Simple sanity checks for java.nio.file.FileSystem
  */
 public class Basic {
 
     static void check(boolean okay, String msg) {
         if (!okay)

@@ -46,11 +49,29 @@
             check(fs.supportedFileAttributeViews().contains(view),
                 "support for '" + view + "' expected");
         }
     }
 
-    public static void main(String[] args) throws IOException {
+    static void checkNoUOE() throws IOException, URISyntaxException {
+        String dir = System.getProperty("test.dir", ".");
+        String fileName = dir + File.separator + "foo.bar";
+        Path path = Paths.get(fileName);
+        Path file = Files.createFile(path);
+        try {
+            URI uri = new URI("jar", file.toUri().toString(), null);
+            System.out.println(uri);
+            FileSystem fs = FileSystems.newFileSystem(uri, new HashMap());
+            fs.close();
+        } catch (ProviderNotFoundException pnfe) {
+            System.out.println("Expected ProviderNotFoundException caught: "
+                + "\"" + pnfe.getMessage() + "\"");
+        } finally {
+            Files.delete(path);
+        }
+    }
+
+    public static void main(String[] args) throws IOException, URISyntaxException {
         FileSystem fs = FileSystems.getDefault();
 
         // close should throw UOE
         try {
             fs.close();

@@ -78,7 +99,11 @@
             checkSupported(fs, "posix", "unix", "owner", "dos", "user");
         if (os.contains("OS X"))
             checkSupported(fs, "posix", "unix", "owner");
         if (os.equals("Windows"))
             checkSupported(fs, "owner", "dos", "acl", "user");
+
+        // sanity check non-throwing of UnsupportedOperationException by
+        // FileSystems.newFileSystem(URI, ..)
+        checkNoUOE();
     }
 }