8135108: java/util/zip/TestLocalTime.java fails intermittently with Invalid value for NanoOfSecond
authorsherman
Mon, 15 Feb 2016 18:41:23 -0800
changeset 35976 9fdca6a099c1
parent 35975 6ed1de57b086
child 35977 3490843d28ef
8135108: java/util/zip/TestLocalTime.java fails intermittently with Invalid value for NanoOfSecond Reviewed-by: darcy
jdk/src/java.base/share/classes/java/util/zip/ZipEntry.java
jdk/test/java/util/zip/TestLocalTime.java
--- a/jdk/src/java.base/share/classes/java/util/zip/ZipEntry.java	Mon Feb 15 13:37:22 2016 -0800
+++ b/jdk/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/jdk/test/java/util/zip/TestLocalTime.java	Mon Feb 15 13:37:22 2016 -0800
+++ b/jdk/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);
         }