diff --git a/jdk/src/java.base/share/classes/java/nio/file/FileSystems.java b/jdk/src/java.base/share/classes/java/nio/file/FileSystems.java index 8524518f9f3..a5216b9196d 100644 --- a/jdk/src/java.base/share/classes/java/nio/file/FileSystems.java +++ b/jdk/src/java.base/share/classes/java/nio/file/FileSystems.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2007, 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 @@ -321,9 +321,12 @@ public final class FileSystems { String scheme = uri.getScheme(); // check installed providers - for (FileSystemProvider provider: FileSystemProvider.installedProviders()) { + for (FileSystemProvider provider : FileSystemProvider.installedProviders()) { if (scheme.equalsIgnoreCase(provider.getScheme())) { - return provider.newFileSystem(uri, env); + try { + return provider.newFileSystem(uri, env); + } catch (UnsupportedOperationException uoe) { + } } } @@ -331,9 +334,12 @@ public final class FileSystems { if (loader != null) { ServiceLoader sl = ServiceLoader .load(FileSystemProvider.class, loader); - for (FileSystemProvider provider: sl) { + for (FileSystemProvider provider : sl) { if (scheme.equalsIgnoreCase(provider.getScheme())) { - return provider.newFileSystem(uri, env); + try { + return provider.newFileSystem(uri, env); + } catch (UnsupportedOperationException uoe) { + } } } } diff --git a/jdk/test/java/nio/file/FileSystem/Basic.java b/jdk/test/java/nio/file/FileSystem/Basic.java index 89903611b4f..481392929ce 100644 --- a/jdk/test/java/nio/file/FileSystem/Basic.java +++ b/jdk/test/java/nio/file/FileSystem/Basic.java @@ -1,5 +1,5 @@ /* - * 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 @@ -22,17 +22,23 @@ */ /* @test - * @bug 4313887 6838333 + * @bug 4313887 6838333 8132497 * @summary Unit test for java.nio.file.FileSystem - * @library .. + * @library .. /lib/testlibrary + * @build jdk.testlibrary.FileUtils + * @run main/othervm Basic */ +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; +import jdk.testlibrary.FileUtils; /** - * Simple santity checks for java.nio.file.FileSystem + * Simple sanity checks for java.nio.file.FileSystem */ public class Basic { @@ -48,7 +54,25 @@ public class Basic { } } - 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 { + FileUtils.deleteFileWithRetry(path); + } + } + + public static void main(String[] args) throws IOException, URISyntaxException { FileSystem fs = FileSystems.getDefault(); // close should throw UOE @@ -80,5 +104,9 @@ public class Basic { 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(); } }