Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8346722

(fs) Files.probeContentType throws ClassCastException with custom file system provider

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 25
    • None
    • core-libs
    • None
    • b06
    • linux, os_x

      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

            bpb Brian Burkhalter
            mkartashev Maxim Kartashev
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: