8068790: ZipEntry/JarEntry.setCreation/LastAccessTime(null) don't throw NPE as specified
Reviewed-by: coffeys, sherman
--- 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
+ }
+ }
}