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

(zipfs) ZipPath.isSameFile() should always return true if this Path and the given Path are equal.

XMLWordPrintable

    • b128
    • generic
    • generic
    • Verified

      JDK version: 7-pro-b123

      http://download.oracle.com/javase/7/docs/api/java/nio/file/Path.html#isSameFile(java.nio.file.Path) says:
      ========================
      isSameFile

      public abstract boolean isSameFile(Path other)
                                  throws IOException
      Tests if the file referenced by this object is the same file referenced by another object.
      * If this Path and the given Path are equal then this method returns true without checking if the file exists. *
      ========================

      This is true for default file system but not true for zip fils system. See the following code and output:

      =====Begin of Code=====
      import java.io.IOException;
      import java.nio.file.FileSystems;
      import java.nio.file.Path;
      import java.nio.file.Paths;
      import java.util.HashMap;
      import java.util.Map;

      import com.sun.nio.zipfs.ZipFileSystem;

      import static java.lang.System.out;;

      public class IsSameFile {

      public static void main(String[] args) throws IOException {
      Map<String, Object> env = new HashMap<String, Object>();
      env.put("create", "true");
      Path file = Paths.get("place_holder.zip");
      file.deleteIfExists();
      ZipFileSystem fs = (ZipFileSystem) FileSystems.newFileSystem(file, env,
      null);

      String nofile = "noSuchFile";

      // test against default fs
      out.println("test against default fs:");
      out.println("exists? " + Paths.get(nofile).exists());
      out.println("equals? " + Paths.get(nofile).equals(Paths.get(nofile)));
      out.println(Paths.get(nofile).isSameFile(Paths.get(nofile)));

      // test against Zip fs
      out.println("test against zip fs:");
      out.println("exists? " + fs.getPath(nofile).exists());
      out.println("equals? " + fs.getPath(nofile).equals(fs.getPath(nofile)));
      out.println(fs.getPath(nofile).isSameFile(fs.getPath(nofile)));

      fs.close();
      }
      }

      =====End of Code=====

      =====Begin of Output=====
      test against default fs:
      exists? false
      equals? true
      true
      test against zip fs:
      exists? false
      equals? true
      Exception in thread "main" java.nio.file.NoSuchFileException: noSuchFile
      at com.sun.nio.zipfs.ZipPath.checkAccess(ZipPath.java:825)
      at com.sun.nio.zipfs.ZipPath.isSameFile(ZipPath.java:732)
      at IsSameFile.main(IsSameFile.java:34)

      =====End of Output=====

            sherman Xueming Shen
            stephenh Stephen Hu (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: