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

Print this page
rev 12534 : 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: chegar

*** 1,7 **** /* ! * Copyright (c) 2008, 2012, 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. --- 1,7 ---- /* ! * 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,40 **** * or visit www.oracle.com if you need additional information or have any * questions. */ /* @test ! * @bug 4313887 6838333 * @summary Unit test for java.nio.file.FileSystem ! * @library .. */ import java.nio.file.*; - import java.nio.file.attribute.*; import java.io.IOException; /** ! * Simple santity checks for java.nio.file.FileSystem */ public class Basic { static void check(boolean okay, String msg) { if (!okay) --- 20,46 ---- * or visit www.oracle.com if you need additional information or have any * questions. */ /* @test ! * @bug 4313887 6838333 8132497 * @summary Unit test for java.nio.file.FileSystem ! * @library .. /lib/testlibrary ! * @build jdk.testlibrary.FileUtils ! * @run main/othervm Basic */ + import java.io.File; import java.nio.file.*; import java.io.IOException; + import java.net.URI; + import java.net.URISyntaxException; + import java.util.HashMap; + import jdk.testlibrary.FileUtils; /** ! * Simple sanity checks for java.nio.file.FileSystem */ public class Basic { static void check(boolean okay, String msg) { if (!okay)
*** 46,56 **** check(fs.supportedFileAttributeViews().contains(view), "support for '" + view + "' expected"); } } ! public static void main(String[] args) throws IOException { FileSystem fs = FileSystems.getDefault(); // close should throw UOE try { fs.close(); --- 52,80 ---- check(fs.supportedFileAttributeViews().contains(view), "support for '" + view + "' expected"); } } ! 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 { ! FileUtils.deleteFileWithRetry(path); ! } ! } ! ! public static void main(String[] args) throws IOException, URISyntaxException { FileSystem fs = FileSystems.getDefault(); // close should throw UOE try { fs.close();
*** 78,84 **** --- 102,112 ---- 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(); } }