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

ZipEntry.isDirectory() may return false incorrectly

    XMLWordPrintable

Details

    • b126
    • other
    • 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

      Attachments

        Issue Links

          There are no Sub-Tasks for this issue.

          Activity

            People

              sherman Xueming Shen
              elarsen Erik Larsen (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: