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 **** /* ! * 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,43 ---- * 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 .. */ + import java.io.File; import java.nio.file.*; import java.io.IOException; + import java.net.URI; + import java.net.URISyntaxException; + import java.util.HashMap; /** ! * 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(); --- 49,77 ---- 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 { ! Files.delete(path); ! } ! } ! ! public static void main(String[] args) throws IOException, URISyntaxException { FileSystem fs = FileSystems.getDefault(); // close should throw UOE try { fs.close();
*** 78,84 **** --- 99,109 ---- 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(); } }