Unix default file type detector assumes a concrete file system (UnixFileSystemProvider) and consequently cannot be used when the file system has been overridden with -Djava.nio.file.spi.DefaultFileSystemProvider.
To reproduce:
1. Compile testfsp.TestProvider from test/jdk/java/nio/file/spi/testfsp in the OpenJDK project repo
2. Compile this test class Test.java
public class Test {
public static void main(String args[]) throws Exception {
System.out.println(java.nio.file.Files.probeContentType(java.nio.file.Path.of(".")));
}
}
3. Run java like so
$ java -Djava.nio.file.spi.DefaultFileSystemProvider=testfsp.TestProvider Test
Observe the exceptions:
Exception in thread "main" java.lang.ExceptionInInitializerError
at java.base/java.nio.file.Files.probeContentType(Files.java:1584)
at Test.main(Test.java:3)
Caused by: java.lang.ClassCastException: class testfsp.TestProvider cannot be cast to class sun.nio.fs.UnixFileSystemProvider (testfsp.TestProvider is in unnamed module of loader 'app'; sun.nio.fs.UnixFileSystemProvider is in module java.base of loader 'bootstrap')
at java.base/sun.nio.fs.DefaultFileTypeDetector.create(DefaultFileTypeDetector.java:37)
at java.base/java.nio.file.Files$FileTypeDetectors.createDefaultFileTypeDetector(Files.java:1520)
at java.base/java.nio.file.Files$FileTypeDetectors.<clinit>(Files.java:1514)
... 2 more
To reproduce:
1. Compile testfsp.TestProvider from test/jdk/java/nio/file/spi/testfsp in the OpenJDK project repo
2. Compile this test class Test.java
public class Test {
public static void main(String args[]) throws Exception {
System.out.println(java.nio.file.Files.probeContentType(java.nio.file.Path.of(".")));
}
}
3. Run java like so
$ java -Djava.nio.file.spi.DefaultFileSystemProvider=testfsp.TestProvider Test
Observe the exceptions:
Exception in thread "main" java.lang.ExceptionInInitializerError
at java.base/java.nio.file.Files.probeContentType(Files.java:1584)
at Test.main(Test.java:3)
Caused by: java.lang.ClassCastException: class testfsp.TestProvider cannot be cast to class sun.nio.fs.UnixFileSystemProvider (testfsp.TestProvider is in unnamed module of loader 'app'; sun.nio.fs.UnixFileSystemProvider is in module java.base of loader 'bootstrap')
at java.base/sun.nio.fs.DefaultFileTypeDetector.create(DefaultFileTypeDetector.java:37)
at java.base/java.nio.file.Files$FileTypeDetectors.createDefaultFileTypeDetector(Files.java:1520)
at java.base/java.nio.file.Files$FileTypeDetectors.<clinit>(Files.java:1514)
... 2 more
- links to
-
Commit(master) openjdk/jdk/4b554b52
-
Review(master) openjdk/jdk/23019