8132497: (fs) FileSystems.newFileSystem(URI, ..) doesn't handle UOE thrown by provider

Handle UOEs in newFileSystem(URI,...) similarly to as done in newFileSystem(Path path, ClassLoader loader).

Reviewed-by: chegar
This commit is contained in:
Brian Burkhalter 2015-08-10 10:50:24 -07:00
parent e0803f5e68
commit aabba04bda
2 changed files with 45 additions and 11 deletions

View File

@ -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<FileSystemProvider> 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) {
}
}
}
}

View File

@ -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();
}
}