8062804: IsoFields WEEK_BASED_YEAR and QUARTER_OF_YEAR too lenient
Summary: Addded the necessary chck in IsoFields WEEK_BASED_YEAR and QUARTER_OF_YEAR
Reviewed-by: rriggs, scolebourne
--- a/jdk/src/java.base/share/classes/java/time/temporal/IsoFields.java Tue May 10 13:48:07 2016 -0700
+++ b/jdk/src/java.base/share/classes/java/time/temporal/IsoFields.java Wed May 11 10:28:23 2016 +0000
@@ -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 @@
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 extends Temporal> R adjustInto(R temporal, long newValue) {
@@ -529,6 +535,12 @@
}
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 extends Temporal> R adjustInto(R temporal, long newValue) {
--- a/jdk/test/java/time/tck/java/time/temporal/TCKIsoFields.java Tue May 10 13:48:07 2016 -0700
+++ b/jdk/test/java/time/tck/java/time/temporal/TCKIsoFields.java Wed May 11 10:28:23 2016 +0000
@@ -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 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;
@@ -439,6 +442,29 @@
}
//-----------------------------------------------------------------------
+ // 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
LocalDate date = LocalDate.of(1960, 1, 5); // Tuseday of week 1 1960