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

ZipEntry.getTime() returns modified time of the ZipFile, not the entry.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P4 P4
    • None
    • 1.4.2
    • core-libs

      FULL PRODUCT VERSION :
      java version "1.4.2_05"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_05-b04)
      Java HotSpot(TM) Client VM (build 1.4.2_05-b04, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows XP [Version 5.1.2600]


      EXTRA RELEVANT SYSTEM CONFIGURATION :
      NTFS file system

      A DESCRIPTION OF THE PROBLEM :
      Using java.util.zip.ZipEntry to set and get the time of the entries.

      ZipEntry.setTime(X) works correctly. (Checked via 3rd party zip program).
      However, when using ZipEntry.getTime() it returns the time of the ZipFile, not the time of the Entry in the ZipFile.



      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Create a zip file add entries and set their time stamps.
      See source code

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      for every file passed to the method you should get 2 statements on the console:
      [filename] PreZip: [filetimeinMS]
      InZip: [entrytimeinMS]
      ie.
      c:\test.txt PreZip: 1121699509549
      InZip: 1121699509549


      ACTUAL -
      c:\test.txt PreZip: 1121699509549
      InZip: 1121699508000

      the 2 times should be identical, however, [entrytimeinMS] will be the time of the ZipFile instead. If you open said ZipFile with WinZip etc, the time reported by them for the entries will be correct.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.util.zip.*;
      import java.io.*;

      class test
      {
      public static void main(String[] args)
      {
      String con[] = { "File1", "File2" };
      test t = new test();
      t.createZip("test.zip", con);
      }
      public void createZip(String zipfilename, String[] contents) {
      try {
      ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(zipfilename));

      for (int i=0; i<contents.length; i++) {
      ZipEntry ze = new ZipEntry(contents[i]);
      zos.setMethod(ZipOutputStream.DEFLATED); //indicate deflated
      zos.setLevel(Deflater.DEFAULT_COMPRESSION); //use default level
      zos.putNextEntry(ze);
      File fin = new File(contents[i]);
      FileInputStream ins = new FileInputStream(fin);
      System.out.println(contents[i] + " PreZip: " + fin.lastModified());
      ze.setTime(fin.lastModified());
      System.out.println("InZip: " + ze.getTime());
      int bread;
      byte[] bin = new byte[4096];
      while ( (bread = ins.read(bin, 0, 4096)) > -1) {
      zos.write(bin, 0, bread); }
      zos.closeEntry();
      }
      zos.close();
      }
      catch (Exception x) {
      System.out.println(x.toString());
      }
      }
      }
      ---------- END SOURCE ----------

            martin Martin Buchholz
            ndcosta Nelson Dcosta (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: