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

ZipFile throws ZipException on open a empty zipfile from winzip

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.4.2
    • core-libs

      FULL PRODUCT VERSION :
      1.4.2_04

      ADDITIONAL OS VERSION INFORMATION :
      windows XP SP2 build 2600 version 5.1

      A DESCRIPTION OF THE PROBLEM :
      If I create a ZipFile Object on a File that was made with winzip and the winzip archiv *.zip had no entrys an ZipException is happend.
      If the file contains Entry(s) there is no Exception



      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Create a new File of type winzip without any entrys
      use the programm to list the contents
      on this line of code it happens a ZipException f = new ZipFile(ff);


       /** Liest alle dir Entrys in ArrayList
         *
         * @param archiv String
         * @return ArrayList
         */
        private ArrayList getDirEntrys(String archiv)
        {
          ArrayList al = new ArrayList();
          ZipFile f = null;
          try
          {
            File ff = new File(archiv);
            f = new ZipFile(ff);

            Enumeration enum = f.entries();
            while (enum.hasMoreElements())
            {
              ZipEntry entry = (ZipEntry) enum.nextElement();
              if (entry.isDirectory())
              {
                al.add(entry.getName());
              }
            }
          }
          catch (IOException ioe)
          {
            ioe.printStackTrace();
          }
          finally
          {
            try
            {
              if (f != null)
              {
                f.close();
              }
            }
            catch (Exception ex)
            {
              ex.printStackTrace();
            }
          }
          System.out.println("Found " + al.size() + " Dir entrys");
          return al;
        }


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      no Exception
      ACTUAL -
      java.util.zip.ZipException: error in opening zip file
      at java.util.zip.ZipFile.open(Native Method)
      at java.util.zip.ZipFile.<init>(Unknown Source)
      at java.util.zip.ZipFile.<init>(Unknown Source)


      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      java.util.zip.ZipException: error in opening zip file
      at java.util.zip.ZipFile.open(Native Method)
      at java.util.zip.ZipFile.<init>(Unknown Source)
      at java.util.zip.ZipFile.<init>(Unknown Source)


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      class ziptest
      {
      public static void main(String[] args)
      {
      new ziptest().getDirEntrys("test.zip");
      }
        private ArrayList getDirEntrys(String archiv)
        {
          ArrayList al = new ArrayList();
          ZipFile f = null;
          try
          {
            File ff = new File(archiv);
            f = new ZipFile(ff);

            Enumeration enum1 = f.entries();
            while (enum1.hasMoreElements())
            {
              ZipEntry entry = (ZipEntry) enum1.nextElement();
              if (entry.isDirectory())
              {
                al.add(entry.getName());
              }
            }
          }
          catch (IOException ioe)
          {
            ioe.printStackTrace();
          }
          finally
          {
            try
            {
              if (f != null)
              {
                f.close();
              }
            }
            catch (Exception ex)
            {
              ex.printStackTrace();
            }
          }
          System.out.println("Found " + al.size() + " Dir entrys");
          return al;
        }
      }
      ---------- END SOURCE ----------

            bristor Dave Bristor (Inactive)
            ndcosta Nelson Dcosta (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: