You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by bo...@apache.org on 2015/10/24 08:19:37 UTC

commons-compress git commit: COMPRESS-326 adjust tests to changes in Java's zip package

Repository: commons-compress
Updated Branches:
  refs/heads/master 1e592b52c -> a2cda30be


COMPRESS-326 adjust tests to changes in Java's zip package


Project: http://git-wip-us.apache.org/repos/asf/commons-compress/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-compress/commit/a2cda30b
Tree: http://git-wip-us.apache.org/repos/asf/commons-compress/tree/a2cda30b
Diff: http://git-wip-us.apache.org/repos/asf/commons-compress/diff/a2cda30b

Branch: refs/heads/master
Commit: a2cda30be14b3da01cbbbedc41b70daf6d88da8b
Parents: 1e592b5
Author: Stefan Bodewig <st...@innoq.com>
Authored: Sat Oct 24 08:18:59 2015 +0200
Committer: Stefan Bodewig <st...@innoq.com>
Committed: Sat Oct 24 08:18:59 2015 +0200

----------------------------------------------------------------------
 src/changes/changes.xml                         |  4 ++
 .../compress/archivers/zip/ZipArchiveEntry.java |  8 ++++
 src/site/xdoc/limitations.xml                   |  4 ++
 .../zip/X5455_ExtendedTimestampTest.java        | 43 +++++++++++++-------
 4 files changed, 45 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-compress/blob/a2cda30b/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 7b312a7..8ce601e 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -44,6 +44,10 @@ The <action> type attribute can be add,update,fix,remove.
   <body>
     <release version="1.11" date="not released, yet"
              description="Release 1.11">
+      <action issue="COMPRESS-326" type="fix" date="2015-10-24">
+        Adjusted unit test to updates in Java8 and later that change
+        the logic of ZipEntry#getTime.
+      </action>
       <action issue="COMPRESS-324" type="fix" date="2015-10-06">
         TarArchiveOutputStream will now recognize GNU long name and
         link entries even if the special entry has a different name

http://git-wip-us.apache.org/repos/asf/commons-compress/blob/a2cda30b/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntry.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntry.java b/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntry.java
index 4f66373..13db0ce 100644
--- a/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntry.java
+++ b/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntry.java
@@ -743,6 +743,14 @@ public class ZipArchiveEntry extends java.util.zip.ZipEntry
         }
     }
 
+    /**
+     * Wraps {@link ZipEntry#getTime} with a {@link Date} as the
+     * entry's last modified date.
+     *
+     * <p>Changes to the implementation of {@link ZipEntry#getTime}
+     * leak through and the returned value may depend on your local
+     * time zone as well as your version of Java.</p>
+     */
     public Date getLastModifiedDate() {
         return new Date(getTime());
     }

http://git-wip-us.apache.org/repos/asf/commons-compress/blob/a2cda30b/src/site/xdoc/limitations.xml
----------------------------------------------------------------------
diff --git a/src/site/xdoc/limitations.xml b/src/site/xdoc/limitations.xml
index 686951e..851f93e 100644
--- a/src/site/xdoc/limitations.xml
+++ b/src/site/xdoc/limitations.xml
@@ -165,6 +165,10 @@
          of an archive will not be read correctly by
          <code>ZipArchiveInputStream</code> if it used the STORED
          method.</li>
+         <li><code>ZipArchiveEntry#getLastModifiedDate</code> uses
+         <code>ZipEntry#getTime</code> under the covers which may
+         return different times for the same archive when using
+         different versions onf Java.</li>
        </ul>
      </section>
    </body>

http://git-wip-us.apache.org/repos/asf/commons-compress/blob/a2cda30b/src/test/java/org/apache/commons/compress/archivers/zip/X5455_ExtendedTimestampTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/compress/archivers/zip/X5455_ExtendedTimestampTest.java b/src/test/java/org/apache/commons/compress/archivers/zip/X5455_ExtendedTimestampTest.java
index 4761654..8447669 100644
--- a/src/test/java/org/apache/commons/compress/archivers/zip/X5455_ExtendedTimestampTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/zip/X5455_ExtendedTimestampTest.java
@@ -100,6 +100,11 @@ public class X5455_ExtendedTimestampTest {
         1999's zip time:  Jan 1st, 1999-01-01/00:00:02
         1999's mod time:  Jan 1st, 1999-01-01/00:00:01
         1999's acc time:  Jan 1st, 1999-01-01/00:00:03
+
+        Starting with a patch release of Java8, "zip time" actually
+        uses the extended time stamp field itself and should be the
+        same as "mod time".
+        http://hg.openjdk.java.net/jdk8u/jdk8u/jdk/rev/90df6756406f
          */
 
         File archive = getFile("COMPRESS-210_unix_time_zip_test.zip");
@@ -116,8 +121,10 @@ public class X5455_ExtendedTimestampTest {
                 ZipArchiveEntry zae = en.nextElement();
                 String name = zae.getName();
                 X5455_ExtendedTimestamp xf = (X5455_ExtendedTimestamp) zae.getExtraField(X5455);
-                Date z = adjustFromGMTToExpectedOffset(zae.getLastModifiedDate());
+                Date rawZ = zae.getLastModifiedDate();
                 Date m = xf.getModifyJavaTime();
+                boolean zipTimeUsesExtendedTimestamp = rawZ.equals(m);
+                Date z = zipTimeUsesExtendedTimestamp ? rawZ : adjustFromGMTToExpectedOffset(rawZ);
                 Date a = xf.getAccessJavaTime();
 
                 String zipTime = DATE_FORMAT.format(z);
@@ -136,24 +143,30 @@ public class X5455_ExtendedTimestampTest {
                     if (year >= 0) {
                         switch (year) {
                             case 2107:
-                                // Zip time is okay up to 2107.
-                                assertEquals(year + "-01-01/00:00:02 +0000", zipTime);
+                                if (!zipTimeUsesExtendedTimestamp) {
+                                    // Zip time is okay up to 2107.
+                                    assertEquals(year + "-01-01/00:00:02 +0000", zipTime);
+                                }
                                 // But the X5455 data has overflowed:
                                 assertEquals("1970-11-24/17:31:45 +0000", modTime);
                                 assertEquals("1970-11-24/17:31:47 +0000", accTime);
                                 break;
                             case 2108:
-                                // Zip time is still okay at Jan 1st midnight (UTC) in 2108
-                                // because we created the zip file in pacific time zone, so it's
-                                // actually still 2107 in the zip file!
-                                assertEquals(year + "-01-01/00:00:02 +0000", zipTime);
+                                if (!zipTimeUsesExtendedTimestamp) {
+                                    // Zip time is still okay at Jan 1st midnight (UTC) in 2108
+                                    // because we created the zip file in pacific time zone, so it's
+                                    // actually still 2107 in the zip file!
+                                    assertEquals(year + "-01-01/00:00:02 +0000", zipTime);
+                                }
                                 // The X5455 data is still overflowed, of course:
                                 assertEquals("1971-11-24/17:31:45 +0000", modTime);
                                 assertEquals("1971-11-24/17:31:47 +0000", accTime);
                                 break;
                             case 2109:
                                 // All three timestamps have overflowed by 2109.
-                                assertEquals("1981-01-01/00:00:02 +0000", zipTime);
+                                if (!zipTimeUsesExtendedTimestamp) {
+                                    assertEquals("1981-01-01/00:00:02 +0000", zipTime);
+                                }
                                 assertEquals("1972-11-24/17:31:45 +0000", modTime);
                                 assertEquals("1972-11-24/17:31:47 +0000", accTime);
 
@@ -163,12 +176,14 @@ public class X5455_ExtendedTimestampTest {
 
                                 break;
                             default:
-                                // X5455 time is good from epoch (1970) to 2106.
-                                // Zip time is good from 1980 to 2107.
-                                if (year < 1980) {
-                                    assertEquals("1980-01-01/08:00:00 +0000", zipTime);
-                                } else {
-                                    assertEquals(year + "-01-01/00:00:02 +0000", zipTime);
+                                if (!zipTimeUsesExtendedTimestamp) {
+                                    // X5455 time is good from epoch (1970) to 2106.
+                                    // Zip time is good from 1980 to 2107.
+                                    if (year < 1980) {
+                                        assertEquals("1980-01-01/08:00:00 +0000", zipTime);
+                                    } else {
+                                        assertEquals(year + "-01-01/00:00:02 +0000", zipTime);
+                                    }
                                 }
                                 assertEquals(year + "-01-01/00:00:01 +0000", modTime);
                                 assertEquals(year + "-01-01/00:00:03 +0000", accTime);