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

(zipfs) ZipPath should throw ProviderMismatchException when invoking register()

XMLWordPrintable

    • b121
    • x86_64
    • windows_7
    • Verified

      FULL PRODUCT VERSION :
      java version "1.8.0_66"
      Java(TM) SE Runtime Environment (build 1.8.0_66-b18)
      Java HotSpot(TM) 64-Bit Server VM (build 25.66-b18, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 6.1.7601]

      A DESCRIPTION OF THE PROBLEM :
      The java.nio.file package documentation states: "Unless otherwise noted, invoking a method of any class or interface in this package created by one provider with a parameter that is an object created by another provider, will throw ProviderMismatchException."

      However, this is not always the case for Paths of the zipfs FileSystem, namely when invoking register() with a WatchService that was created by another provider. In this case, it throws an UnsupportedOperationException instead.

      Please see below for a test case.

      I think the fix is as simple as replacing UnsupportedOperationException with ProviderMismatchException on the following line:
      http://hg.openjdk.java.net/jdk9/dev/jdk/file/tip/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipPath.java#l572


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      - create a .zip file
      - make sure the test case finds the .zip file at the expected location
      - run the test case


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      a ProviderMismatchException is thrown
      ACTUAL -
      an UnsupportedOperationException is thrown

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.io.IOException;
      import java.nio.file.FileSystems;
      import java.nio.file.Path;
      import java.nio.file.Paths;
      import java.nio.file.StandardWatchEventKinds;

      public class ZipIssue {

      public static void main(String[] args) throws IOException {
      Path zip = Paths.get("archive.zip");
      Path root = FileSystems.newFileSystem(zip, null).getPath("/");
      root.register(FileSystems.getDefault().newWatchService(), StandardWatchEventKinds.ENTRY_CREATE);
      }

      }

      ---------- END SOURCE ----------

            sherman Xueming Shen
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: