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

method ZipEntry.setTime(long) works incorrectly

    XMLWordPrintable

Details

    • Bug
    • Status: Closed
    • P4
    • Resolution: Fixed
    • 1.2.1, 1.4.1
    • 8
    • core-libs
    • b94
    • generic, sparc
    • generic, solaris_7
    • Verified

    Description

      Name: vpR10011 Date: 10/08/2002



      Java 2 Platform Std.Ed. v1.4.1 API specification of the method
      java.util.zip.ZipEntry.setTime(long) says:
      "public void setTime(long time)

      Sets the modification time of the entry.
      Parameters:
          time - the entry modification time in number of milliseconds since the
                 epoch"
          
      Specification of constructor java.util.Date(long) defines "the epoch":
      "...the standard base time known as "the epoch", namely January 1, 1970,
      00:00:00 GMT".

      Moreover, Java 2 Platform Std.Ed v1.4.1 API specification refers
      to "GZIP file format specification version 4.3 (RFC 1952)" which defines
      modification time as:
      "MTIME (Modification TIME)
          This gives the most recent modification time of the original
          file being compressed. The time is in Unix format, i.e.,
          seconds since 00:00:00 GMT, Jan. 1, 1970. (Note that this
          may cause problems for MS-DOS and other systems that use
          local rather than Universal time.) If the compressed data
          did not come from a file, MTIME is set to the time at which
          compression started. MTIME = 0 means no time stamp is
          available."
          
          
      But the method java.util.zip.ZipEntry.setTime(long) rejects modification
      time if it is less than January 1, 1980, 00:00:00 GMT.

      To reproduce this bug run the following test:
      -----------test1.java------------
      import java.io.PrintStream;
      import java.util.zip.*;
      import java.util.Date;

      public class test1{

          private static String testString = "ZipEntryTest";
          public static void main(String argv[]) {
              ZipEntry ze = new ZipEntry("ZipEntryTest");
              Date date = new Date(10);
              ze.setTime(date.getTime());
              System.out.println("date.getTime(): "+date.getTime());
              System.out.println("ze.getTime(): "+ze.getTime());
              Date date1 = new Date(ze.getTime());
              System.out.println(date);
              System.out.println(date1);
          }
      }
      --------------------- Output ------------------------
      % javac -d . test1.java
      % java -version
      java version "1.4.1"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1-b21)
      Java HotSpot(TM) Client VM (build 1.4.1-b21, mixed mode)
      % java test1
      date.getTime(): 10
      ze.getTime(): 315511200000
      Thu Jan 01 06:00:00 GMT+06:00 1970
      Tue Jan 01 00:00:00 GMT+06:00 1980
      -----------------------------------

      ======================================================================

      Attachments

        Issue Links

          Activity

            People

              sherman Xueming Shen
              verapsunw Verap Verap (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: