From d9fa6e798c9e330a16caecc916138175b77d46df Mon Sep 17 00:00:00 2001 From: robm Date: Fri, 4 Dec 2015 18:40:59 +0000 Subject: [PATCH] 8067800: Clarify java.time.chrono.Chronology.isLeapYear for out of range years Reviewed-by: rriggs --- .../java/time/chrono/HijrahChronology.java | 5 ++--- .../time/chrono/TestUmmAlQuraChronology.java | 20 +++++++++++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/share/classes/java/time/chrono/HijrahChronology.java b/src/share/classes/java/time/chrono/HijrahChronology.java index 6291b9ce5..602409f75 100644 --- a/src/share/classes/java/time/chrono/HijrahChronology.java +++ b/src/share/classes/java/time/chrono/HijrahChronology.java @@ -545,9 +545,8 @@ public final class HijrahChronology extends AbstractChronology implements Serial @Override public boolean isLeapYear(long prolepticYear) { checkCalendarInit(); - int epochMonth = yearToEpochMonth((int) prolepticYear); - if (epochMonth < 0 || epochMonth > maxEpochDay) { - throw new DateTimeException("Hijrah date out of range"); + if (prolepticYear < getMinimumYear() || prolepticYear > getMaximumYear()) { + return false; } int len = getYearLength((int) prolepticYear); return (len > 354); diff --git a/test/java/time/test/java/time/chrono/TestUmmAlQuraChronology.java b/test/java/time/test/java/time/chrono/TestUmmAlQuraChronology.java index 9fbe6d1c0..ff64add43 100644 --- a/test/java/time/test/java/time/chrono/TestUmmAlQuraChronology.java +++ b/test/java/time/test/java/time/chrono/TestUmmAlQuraChronology.java @@ -30,6 +30,7 @@ import static java.time.temporal.ChronoField.DAY_OF_YEAR; import static java.time.temporal.ChronoField.MONTH_OF_YEAR; import static java.time.temporal.ChronoField.YEAR; import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertTrue; import static org.testng.Assert.fail; @@ -71,6 +72,7 @@ import org.testng.annotations.Test; /** * Tests for the Umm alQura chronology and data. * Note: The dates used for testing are just a sample of calendar data. + * @bug 8067800 */ @Test public class TestUmmAlQuraChronology { @@ -530,6 +532,24 @@ public class TestUmmAlQuraChronology { assertEquals(date.isLeapYear(), leapyear); } + // Data provider to verify that a given hijrah year is outside the range of supported years + // The values are dependent on the currently configured UmmAlQura calendar data + @DataProvider(name="OutOfRangeLeapYears") + Object[][] data_invalid_leapyears() { + return new Object[][] { + {1299}, + {1601}, + {Integer.MAX_VALUE}, + {Integer.MIN_VALUE}, + }; + } + + @Test(dataProvider="OutOfRangeLeapYears") + public void test_notLeapYears(int y) { + assertFalse(HijrahChronology.INSTANCE.isLeapYear(y), "Out of range leap year"); + } + + // Date samples to convert HijrahDate to LocalDate and vice versa @DataProvider(name="samples") Object[][] data_samples() { -- GitLab