mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-26 14:24:46 +02:00
8346573: Can't use custom default file system provider with custom system class loader
Reviewed-by: mkartashev, bpb
This commit is contained in:
parent
379ac349d1
commit
f1196638b3
3 changed files with 70 additions and 14 deletions
|
@ -34,6 +34,7 @@ import java.util.Map;
|
|||
import java.util.ServiceConfigurationError;
|
||||
import java.util.ServiceLoader;
|
||||
|
||||
import jdk.internal.loader.ClassLoaders;
|
||||
import jdk.internal.misc.VM;
|
||||
import sun.nio.fs.DefaultFileSystemProvider;
|
||||
|
||||
|
@ -112,11 +113,9 @@ public final class FileSystems {
|
|||
if (propValue != null) {
|
||||
for (String cn: propValue.split(",")) {
|
||||
try {
|
||||
Class<?> c = Class
|
||||
.forName(cn, true, ClassLoader.getSystemClassLoader());
|
||||
Constructor<?> ctor = c
|
||||
.getDeclaredConstructor(FileSystemProvider.class);
|
||||
provider = (FileSystemProvider)ctor.newInstance(provider);
|
||||
Class<?> c = Class.forName(cn, true, ClassLoaders.appClassLoader());
|
||||
Constructor<?> ctor = c.getDeclaredConstructor(FileSystemProvider.class);
|
||||
provider = (FileSystemProvider) ctor.newInstance(provider);
|
||||
|
||||
// must be "file"
|
||||
if (!provider.getScheme().equals("file"))
|
||||
|
@ -146,13 +145,17 @@ public final class FileSystems {
|
|||
* is invoked to create the default file system.
|
||||
*
|
||||
* <p> If the system property {@code java.nio.file.spi.DefaultFileSystemProvider}
|
||||
* is defined then it is taken to be a list of one or more fully-qualified
|
||||
* names of concrete provider classes identified by the URI scheme
|
||||
* {@code "file"}. Where the property is a list of more than one name then
|
||||
* the names are separated by a comma. Each class is loaded, using the system
|
||||
* class loader, and instantiated by invoking a one argument constructor
|
||||
* whose formal parameter type is {@code FileSystemProvider}. The providers
|
||||
* are loaded and instantiated in the order they are listed in the property.
|
||||
* is defined then it is taken to be a list of one or more fully-qualified names
|
||||
* of concrete provider classes identified by the URI scheme {@code "file"}.
|
||||
* If the property is a list of more than one name then the names are separated
|
||||
* by a comma character. Each provider class is a {@code public} class with a
|
||||
* {@code public} constructor that has one formal parameter of type {@code
|
||||
* FileSystemProvider}. If the provider class is in a named module then the module
|
||||
* exports the package containing the provider class to at least {@code java.base}.
|
||||
* Each provider class is loaded, using the
|
||||
* {@linkplain ClassLoader#getSystemClassLoader() default system class loader},
|
||||
* and instantiated by invoking the constructor. The providers are loaded and
|
||||
* instantiated in the order they are listed in the property.
|
||||
* If this process fails or a provider's scheme is not equal to {@code "file"}
|
||||
* then an unspecified error is thrown. URI schemes are normally compared
|
||||
* without regard to case but for the default provider, the scheme is
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue