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

ZipEntry.isDirectory() may return false incorrectly

    Details

    • Subcomponent:
    • Resolved In Build:
      b126
    • CPU:
      other
    • OS:
      windows_xp

      Description

      Operating System(s) : Win32, Windows XP

      Full JDK version(s) (from java -version)

      java version "1.5.0"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-b64)
      Java HotSpot(TM) Client VM (build 1.5.0-b64, mixed mode)

      The problem is recreatable on all the SUN JDK versions namely 131,141 and 142 .
        
      1. Create a JAR with directory entries (Win32)
      2. mkdir t
      3. cd t
      4. mkdir a
      5. jar -cf foo.jar *
      6. java Test foo.jar

      What you will see is that both jarFile.getEntry("a/"); and jarFile.getEntry("a") return a
      ZipEntry/JarEntry, however only "a/" reports that its a directory. The JarEntry for "a" is also a
      directory but since it doesn't end with /, the isDirectory API doesn't correctly report it.

      The problem is in the ZipFile.getEntry() code. It falls back to looking
      for "a/" as an entry, but then creates the entry based on the name
      passed in. ZipFile.isDirectory looks for the ending "/" which does not
      exist.

      Testcase:

      import java.io.IOException;
      import java.util.jar.JarFile;
      import java.util.zip.ZipEntry;

      public class Test {
       public static void main(String args[]) {
        try {
         JarFile jf = new JarFile(args[0]);
         ZipEntry je = jf.getEntry("a/");
         System.out.println(je.getName() + " " + je.isDirectory());
         je = jf.getEntry("a");
         System.out.println(je.getName() + " " + je.isDirectory());
        } catch (IOException e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
        }
       }



      ###@###.### 2005-2-25 19:52:07 GMT

        Issue Links

          Activity

          Hide
          martin Martin Buchholz added a comment -
          BT2:EVALUATION

          The submitter is correct.
          The entry name should be canonicalized to the name
          actually stored in the zip file, which is required to
          end in "/" for directories.
          ###@###.### 2005-2-25 21:46:28 GMT
          Show
          martin Martin Buchholz added a comment - BT2:EVALUATION The submitter is correct. The entry name should be canonicalized to the name actually stored in the zip file, which is required to end in "/" for directories. ###@###.### 2005-2-25 21:46:28 GMT
          Hide
          hgupdate HG Updates added a comment -
          URL: http://hg.openjdk.java.net/jdk9/dev/jdk/rev/13d951aed7aa
          User: sherman
          Date: 2016-06-28 22:36:28 +0000
          Show
          hgupdate HG Updates added a comment - URL: http://hg.openjdk.java.net/jdk9/dev/jdk/rev/13d951aed7aa User: sherman Date: 2016-06-28 22:36:28 +0000
          Hide
          hgupdate HG Updates added a comment -
          URL: http://hg.openjdk.java.net/jdk9/jdk9/jdk/rev/13d951aed7aa
          User: lana
          Date: 2016-07-06 20:17:35 +0000
          Show
          hgupdate HG Updates added a comment - URL: http://hg.openjdk.java.net/jdk9/jdk9/jdk/rev/13d951aed7aa User: lana Date: 2016-07-06 20:17:35 +0000

            People

            • Assignee:
              sherman Xueming Shen
              Reporter:
              elarsen Erik Larsen (Inactive)
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Imported:
                Indexed: