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

(fs) FileSystems.newFileSystem(Path, Map) does not specify how providers should behave when file does not exist

XMLWordPrintable

    • generic
    • generic

      ADDITIONAL SYSTEM INFORMATION :
      I've tried Windows 10, Linux and FreeBSD with JDK 18 (build 18+36-2087) and 17 (build 17.0.2+8-1).

      A DESCRIPTION OF THE PROBLEM :
      FileSystems.newFileSystem(Path, Map<String, ?>) call should allow to create pseudo-file systems contained in regular files (as opposite to filesystems identified by URI).
      Problem is, ZipFileSystemProvider try to open/create ZIP file even if path points to file with other (not ".zip" or ".jar") extension, which prevents other providers to work.
      If here is custom FileSystemProvider (say, for other archive format) it will never be called if it is registered later than ZipFileSystemProvider.

      I have custom provider which supports files with ".blfs" extension. When I try to call

      There could be several scenarios:

      (1) File "container.blfs" DOESN'T exist:
        (a) FileSystem fs = FileSystems.newFileSystem(Path.of("container.blfs"), Map.of("create", true));
            File "container.blfs" will be created and will be ZIP archive. My custom provider WILL NOT be called.
        (b) FileSystem fs = FileSystems.newFileSystem(Path.of("container.blfs"), Map.of());
            NoSuchFileException will be thrown by ZipFileSystemProvider and it will propagate into my (client) code.
      (2) File "container.blfs" EXISTS and IS NOT a ZIP archive:
        (a) FileSystem fs = FileSystems.newFileSystem(Path.of("container.blfs"), Map.of("create", true));
            ZipFileSystemProvider throws UnsupportedOperationException(), it will be suppressed, my custom provider will be called.

      So, there is NO WAY to create container for custom filesystem provider via this API.

      Bug JDK-7007596 tried to fix this, but it fixed only case when passed path points to directory.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Create and register custom FileSystemProvider which works with regular files (not URIs). Try to create such file via FileSystems.newFileSystem().

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Proper FileSystem instance will be created.
      ACTUAL -
      ZipFileSystem instance will be created or ZipFileSystem will complain about nonexisting file.

      ---------- BEGIN SOURCE ----------
      Sorry, it is confidential, and "empty" custom FileSystem is too large to post here.
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Not found.

      FREQUENCY : always


            lancea Lance Andersen
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: