8160681: LocalDate.ofEpochDay input validation
Summary: Change the EpochDay range to [-365243219162L, 365241780471L]
Reviewed-by: rriggs, scolebourne
--- a/jdk/src/java.base/share/classes/java/time/LocalDate.java Thu Jul 28 10:28:21 2016 +0000
+++ b/jdk/src/java.base/share/classes/java/time/LocalDate.java Thu Jul 28 11:18:43 2016 +0000
@@ -338,6 +338,7 @@
* @throws DateTimeException if the epoch day exceeds the supported date range
*/
public static LocalDate ofEpochDay(long epochDay) {
+ EPOCH_DAY.checkValidValue(epochDay);
long zeroDay = epochDay + DAYS_0000_TO_1970;
// find the march-based year
zeroDay -= 60; // adjust to 0000-03-01 so leap day is at end of four year cycle
--- a/jdk/src/java.base/share/classes/java/time/temporal/ChronoField.java Thu Jul 28 10:28:21 2016 +0000
+++ b/jdk/src/java.base/share/classes/java/time/temporal/ChronoField.java Thu Jul 28 11:18:43 2016 +0000
@@ -427,8 +427,11 @@
* <p>
* This field is strictly defined to have the same meaning in all calendar systems.
* This is necessary to ensure interoperation between calendars.
+ * <p>
+ * Range of EpochDay is between (LocalDate.MIN.toEpochDay(), LocalDate.MAX.toEpochDay())
+ * both inclusive.
*/
- EPOCH_DAY("EpochDay", DAYS, FOREVER, ValueRange.of((long) (Year.MIN_VALUE * 365.25), (long) (Year.MAX_VALUE * 365.25))),
+ EPOCH_DAY("EpochDay", DAYS, FOREVER, ValueRange.of(-365243219162L, 365241780471L)),
/**
* The aligned week within a month.
* <p>