From f2dabbdb6ada125a550cb1e04b6cb10c5cf745a1 Mon Sep 17 00:00:00 2001 From: Bhanu Prakash Gopularam Date: Wed, 11 May 2016 10:28:23 +0000 Subject: [PATCH] 8062804: IsoFields WEEK_BASED_YEAR and QUARTER_OF_YEAR too lenient Addded the necessary chck in IsoFields WEEK_BASED_YEAR and QUARTER_OF_YEAR Reviewed-by: rriggs, scolebourne --- .../classes/java/time/temporal/IsoFields.java | 14 +++++++++- .../tck/java/time/temporal/TCKIsoFields.java | 28 ++++++++++++++++++- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/jdk/src/java.base/share/classes/java/time/temporal/IsoFields.java b/jdk/src/java.base/share/classes/java/time/temporal/IsoFields.java index 73ebdf40abf..26e7e168446 100644 --- a/jdk/src/java.base/share/classes/java/time/temporal/IsoFields.java +++ b/jdk/src/java.base/share/classes/java/time/temporal/IsoFields.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -402,6 +402,12 @@ public final class IsoFields { long moy = temporal.getLong(MONTH_OF_YEAR); return ((moy + 2) / 3); } + public ValueRange rangeRefinedBy(TemporalAccessor temporal) { + if (isSupportedBy(temporal) == false) { + throw new UnsupportedTemporalTypeException("Unsupported field: QuarterOfYear"); + } + return super.rangeRefinedBy(temporal); + } @SuppressWarnings("unchecked") @Override public R adjustInto(R temporal, long newValue) { @@ -529,6 +535,12 @@ public final class IsoFields { } return getWeekBasedYear(LocalDate.from(temporal)); } + public ValueRange rangeRefinedBy(TemporalAccessor temporal) { + if (isSupportedBy(temporal) == false) { + throw new UnsupportedTemporalTypeException("Unsupported field: WeekBasedYear"); + } + return super.rangeRefinedBy(temporal); + } @SuppressWarnings("unchecked") @Override public R adjustInto(R temporal, long newValue) { diff --git a/jdk/test/java/time/tck/java/time/temporal/TCKIsoFields.java b/jdk/test/java/time/tck/java/time/temporal/TCKIsoFields.java index d607571aba1..d1092d15ee6 100644 --- a/jdk/test/java/time/tck/java/time/temporal/TCKIsoFields.java +++ b/jdk/test/java/time/tck/java/time/temporal/TCKIsoFields.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -71,12 +71,15 @@ import static org.testng.Assert.fail; import java.time.DayOfWeek; import java.time.LocalDate; import java.time.LocalDateTime; +import java.time.chrono.ThaiBuddhistDate; import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatterBuilder; import java.time.format.DateTimeParseException; import java.time.format.ResolverStyle; import java.time.temporal.IsoFields; import java.time.temporal.Temporal; +import java.time.temporal.TemporalField; +import java.time.temporal.UnsupportedTemporalTypeException; import java.time.temporal.ValueRange; import org.testng.annotations.DataProvider; @@ -438,6 +441,29 @@ public class TCKIsoFields { assertEquals(parsed, expected); } + //----------------------------------------------------------------------- + // range refinedby + //----------------------------------------------------------------------- + @DataProvider(name="isofields") + Object[][] data_isofields() { + return new Object[][] { + {IsoFields.DAY_OF_QUARTER}, + {IsoFields.QUARTER_OF_YEAR}, + {IsoFields.WEEK_OF_WEEK_BASED_YEAR}, + {IsoFields.WEEK_BASED_YEAR}, + }; + } + + @Test(dataProvider = "isofields") + public void test_isofields_rangerefinedby(TemporalField field) { + field.rangeRefinedBy(LocalDate.now()); + } + + @Test(dataProvider = "isofields", expectedExceptions = UnsupportedTemporalTypeException.class) + public void test_nonisofields_rangerefinedby(TemporalField field) { + field.rangeRefinedBy(ThaiBuddhistDate.now()); + } + //----------------------------------------------------------------------- public void test_loop() { // loop round at least one 400 year cycle, including before 1970