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

(zipfs) ZipPath does not produce correct empty path on relativize()

    Details

    • Subcomponent:
    • Resolved In Build:
      b121
    • CPU:
      generic
    • OS:
      generic
    • Verification:
      Verified

      Description

      FULL PRODUCT VERSION :
      java version "1.8.0_60"
      Java(TM) SE Runtime Environment (build 1.8.0_60-b27)
      Java HotSpot(TM) 64-Bit Server VM (build 25.60-b23, mixed mode)


      ADDITIONAL OS VERSION INFORMATION :
      Mac OS X 10.11

      A DESCRIPTION OF THE PROBLEM :
      ZipPath does not produce a correct "empty path" when relativizing a path against a equal one.



      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
              try (FileSystem fileSystem = FileSystems.newFileSystem(jarFile, Collections.emptyMap())) {
                  Path root = fileSystem.getPath("/");
                  Path root2 = fileSystem.getPath("/");
                  System.out.println(root.relativize(root2).getNameCount());
              }


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      It should print "1" on console. As the definition of en empty path is: "A Path is considered to be an empty path if it consists solely of one name element that is empty."
      ACTUAL -
      Prints "0" on console. This means that "this path only represents a root component" (and is therefore absolute).

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.io.File;
      import java.io.IOException;
      import java.net.URI;
      import java.nio.file.FileSystem;
      import java.nio.file.FileSystems;
      import java.nio.file.Path;
      import java.util.Collections;

      class ZipPathBug {
          public static void main(String[] args) throws IOException {
              URI jarFile = URI.create("jar:" + new File("test.zip").getAbsoluteFile().toURI().toString());
              try (FileSystem fileSystem = FileSystems.newFileSystem(jarFile, Collections.emptyMap())) {
                  Path path = fileSystem.getPath("/foo");
                  Path path2 = fileSystem.getPath("/foo");
                  System.out.println(path.relativize(path2).getNameCount());
              }
          }
      }

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

      CUSTOMER SUBMITTED WORKAROUND :
      As getNameCount() is "0" we can check the relative path and use a workaround specific to this case.

        Attachments

        1. ZipPathBug.java
          0.6 kB
        2. test.zip
          0.6 kB

          Activity

            People

            • Assignee:
              sherman Xueming Shen
              Reporter:
              webbuggrp Webbug Group
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: