8068790: ZipEntry/JarEntry.setCreation/LastAccessTime(null) don't throw NPE as specified
authorredestad
Sat, 21 Feb 2015 13:46:24 +0100
changeset 29095 cb98c9bc4e6d
parent 29094 a4fd2b5e49f8
child 29096 e91fff38083a
8068790: ZipEntry/JarEntry.setCreation/LastAccessTime(null) don't throw NPE as specified Reviewed-by: coffeys, sherman
jdk/src/java.base/share/classes/java/util/zip/ZipEntry.java
jdk/test/java/util/zip/TestExtraTime.java
--- a/jdk/src/java.base/share/classes/java/util/zip/ZipEntry.java	Fri Feb 20 18:32:10 2015 +0300
+++ b/jdk/src/java.base/share/classes/java/util/zip/ZipEntry.java	Sat Feb 21 13:46:24 2015 +0100
@@ -180,8 +180,7 @@
      * @since 1.8
      */
     public ZipEntry setLastModifiedTime(FileTime time) {
-        Objects.requireNonNull(name, "time");
-        this.mtime = time;
+        this.mtime = Objects.requireNonNull(time, "lastModifiedTime");
         this.time = time.to(TimeUnit.MILLISECONDS);
         return this;
     }
@@ -227,8 +226,7 @@
      * @since 1.8
      */
     public ZipEntry setLastAccessTime(FileTime time) {
-        Objects.requireNonNull(name, "time");
-        this.atime = time;
+        this.atime = Objects.requireNonNull(time, "lastAccessTime");
         return this;
     }
 
@@ -265,8 +263,7 @@
      * @since 1.8
      */
     public ZipEntry setCreationTime(FileTime time) {
-        Objects.requireNonNull(name, "time");
-        this.ctime = time;
+        this.ctime = Objects.requireNonNull(time, "creationTime");
         return this;
     }
 
--- a/jdk/test/java/util/zip/TestExtraTime.java	Fri Feb 20 18:32:10 2015 +0300
+++ b/jdk/test/java/util/zip/TestExtraTime.java	Sat Feb 21 13:46:24 2015 +0100
@@ -23,7 +23,7 @@
 
 /**
  * @test
- * @bug 4759491 6303183 7012868 8015666 8023713
+ * @bug 4759491 6303183 7012868 8015666 8023713 8068790
  * @summary Test ZOS and ZIS timestamp in extra field correctly
  */
 
@@ -69,6 +69,8 @@
                 test(mtime, atime, ctime, tz, extra);
             }
         }
+
+        testNullHandling();
     }
 
     static void test(FileTime mtime, FileTime atime, FileTime ctime,
@@ -154,4 +156,26 @@
             }
         }
     }
+
+    static void testNullHandling() {
+        ZipEntry ze = new ZipEntry("TestExtraTime.java");
+        try {
+            ze.setLastAccessTime(null);
+            throw new RuntimeException("setLastAccessTime(null) should throw NPE");
+        } catch (NullPointerException ignored) {
+            // pass
+        }
+        try {
+            ze.setCreationTime(null);
+            throw new RuntimeException("setCreationTime(null) should throw NPE");
+        } catch (NullPointerException ignored) {
+            // pass
+        }
+        try {
+            ze.setLastModifiedTime(null);
+            throw new RuntimeException("setLastModifiedTime(null) should throw NPE");
+        } catch (NullPointerException ignored) {
+            // pass
+        }
+    }
 }