changeset 13722:10e298cb4ef1

8135108: java/util/zip/TestLocalTime.java fails intermittently with Invalid value for NanoOfSecond Reviewed-by: darcy
author sherman
date Mon, 15 Feb 2016 18:41:23 -0800
parents b3ff4bce9d63
children a0317b3da929
files src/java.base/share/classes/java/util/zip/ZipEntry.java test/java/util/zip/TestLocalTime.java
diffstat 2 files changed, 11 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.base/share/classes/java/util/zip/ZipEntry.java	Mon Feb 15 13:37:22 2016 -0800
+++ b/src/java.base/share/classes/java/util/zip/ZipEntry.java	Mon Feb 15 18:41:23 2016 -0800
@@ -227,12 +227,12 @@
         if (year < 0) {
             this.xdostime = DOSTIME_BEFORE_1980;
         } else {
-            this.xdostime = (year << 25 |
+            this.xdostime = ((year << 25 |
                 time.getMonthValue() << 21 |
                 time.getDayOfMonth() << 16 |
                 time.getHour() << 11 |
                 time.getMinute() << 5 |
-                time.getSecond() >> 1)
+                time.getSecond() >> 1) & 0xffffffffL)
                 + ((long)(((time.getSecond() & 0x1) * 1000) +
                       time.getNano() / 1000_000) << 32);
         }
--- a/test/java/util/zip/TestLocalTime.java	Mon Feb 15 13:37:22 2016 -0800
+++ b/test/java/util/zip/TestLocalTime.java	Mon Feb 15 18:41:23 2016 -0800
@@ -23,7 +23,7 @@
 
 /*
  * @test
- * @bug 8075526
+ * @bug 8075526 8135108
  * @key intermittent
  * @summary Test timestamp via ZipEntry.get/setTimeLocal()
  */
@@ -41,6 +41,7 @@
         try {
             LocalDateTime ldt = LocalDateTime.now();
             test(getBytes(ldt), ldt);    // now
+
             ldt = ldt.withYear(1968); test(getBytes(ldt), ldt);
             ldt = ldt.withYear(1970); test(getBytes(ldt), ldt);
             ldt = ldt.withYear(1982); test(getBytes(ldt), ldt);
@@ -55,6 +56,13 @@
             testWithTZ(tz, ldt.withYear(2037));
             testWithTZ(tz, ldt.withYear(2100));
             testWithTZ(tz, ldt.withYear(2106));
+
+            // for #8135108
+            ldt = LocalDateTime.of(2100, 12, 06, 12, 34, 34, 973);
+            test(getBytes(ldt), ldt);
+            ldt = LocalDateTime.of(2106, 12, 06, 12, 34, 34, 973);
+            test(getBytes(ldt), ldt);
+
         } finally {
             TimeZone.setDefault(tz0);
         }