3 Replies Latest reply: Jul 19, 2012 10:24 AM by EJP RSS

    ZipInputStream fails to find a directory entry

    950535
      Before I raise a bug, does anyone think this is working as designed?

      The following testcase:
      import java.io.File;
      import java.io.FileInputStream;
      import java.io.IOException;
      import java.util.zip.ZipEntry;
      import java.util.zip.ZipInputStream;
      
      
      
      public class Zisbug {
      
          public static void main(String[] args) throws IOException {
              File file = new File("src/test/resources/bundle.jar");
              ZipInputStream zis = new ZipInputStream(new FileInputStream(file));
              ZipEntry entry = zis.getNextEntry();
              boolean found = false;
              while (entry != null) {
                  String name = entry.getName();
                  System.out.println(name);
                  if ("META-INF/spring/".equals(name)) {
                      found = true;
                  }
                  entry = zis.getNextEntry();
              }
              if (!found) {
                  System.out.println();
                  System.out.println("Error: Entry 'META-INF/spring/' not found");
              }
      
          }
      
      }
      when run with a JAR containing two files (META-INF/MANIFEST.MF and META-INF/spring/app-context.xml) finds just three entries:
      META-INF/
      META-INF/spring/app-context.xml
      META-INF/MANIFEST.MF
      but fails to find the entry:
      META-INF/spring
      This fails on Mac OS X with either Java 1.6.0_33 or Java 1.7.0_06-ea, on Windows XP with Java 1.6.0_13, and on Ubuntu 12.04 with Java 1.7.0_04.

      A zipfile containing the testcase and JAR file is available here: https://dl.dropbox.com/u/2487064/zisbug.zip. To reproduce the problem, unzip the zip file, change directory into the unzipped file, and issue:
      java -classpath bin Zisbug
      The following output indicates the issue:
      META-INF/
      META-INF/spring/app-context.xml
      META-INF/MANIFEST.MF
      
      Error: Entry 'META-INF/spring/' not found
      Note that jar tf also fails to find the missing entry, so that may indicate either a problem with the JAR or the same issue inside the jar program:
      $ jar tf bundle.jar 
      META-INF/
      META-INF/spring/app-context.xml
      META-INF/MANIFEST.MF
      Re-creating the JAR fixes the problem, so it seems likely that there was a problem in the original JAR.