JDK-6233323 : ZipEntry.isDirectory() may return false incorrectly
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util.jar
  • Affected Version: 5.0
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_xp
  • CPU: other
  • Submitted: 2005-02-25
  • Updated: 2017-07-22
  • Resolved: 2016-06-28
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 9
9 b126Fixed
Related Reports
Relates :  
Sub Tasks
JDK-8173723 :  
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

Comments
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
25-02-2005