8066571: UnsupportedTemporalTypeException is thrown not only in the case of unsupported temporal - Java Bug System
Reviewed-by: rriggs, scolebourne
--- a/jdk/src/java.base/share/classes/java/time/temporal/IsoFields.java Tue Nov 10 15:00:25 2015 +0100
+++ b/jdk/src/java.base/share/classes/java/time/temporal/IsoFields.java Tue Nov 10 14:11:50 2015 -0500
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2015, 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
@@ -102,7 +102,7 @@
* The complete date is expressed using three fields:
* <ul>
* <li>{@link #DAY_OF_QUARTER DAY_OF_QUARTER} - the day within the quarter, from 1 to 90, 91 or 92
- * <li>{@link #QUARTER_OF_YEAR QUARTER_OF_YEAR} - the week within the week-based-year
+ * <li>{@link #QUARTER_OF_YEAR QUARTER_OF_YEAR} - the quarter within the year, from 1 to 4
* <li>{@link ChronoField#YEAR YEAR} - the standard ISO year
* </ul>
*
@@ -571,9 +571,6 @@
//-------------------------------------------------------------------------
private static final int[] QUARTER_DAYS = {0, 90, 181, 273, 0, 91, 182, 274};
- private static boolean isIso(TemporalAccessor temporal) {
- return Chronology.from(temporal).equals(IsoChronology.INSTANCE);
- }
private static void ensureIso(TemporalAccessor temporal) {
if (isIso(temporal) == false) {
@@ -681,7 +678,7 @@
@Override
public boolean isSupportedBy(Temporal temporal) {
- return temporal.isSupported(EPOCH_DAY);
+ return temporal.isSupported(EPOCH_DAY) && isIso(temporal);
}
@SuppressWarnings("unchecked")
@@ -721,4 +718,8 @@
return name;
}
}
+
+ static boolean isIso(TemporalAccessor temporal) {
+ return Chronology.from(temporal).equals(IsoChronology.INSTANCE);
+ }
}
--- a/jdk/test/java/time/test/java/time/temporal/TestIsoWeekFields.java Tue Nov 10 15:00:25 2015 +0100
+++ b/jdk/test/java/time/test/java/time/temporal/TestIsoWeekFields.java Tue Nov 10 14:11:50 2015 -0500
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014,2015, 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
@@ -121,6 +121,14 @@
assertEquals(IsoFields.WEEK_BASED_YEAR.isSupportedBy(ThaiBuddhistDate.now()), false);
}
+ @Test
+ public void test_Unit_isSupportedBy_ISO() {
+ assertEquals(IsoFields.WEEK_BASED_YEARS.isSupportedBy(LocalDate.now()),true);
+ assertEquals(IsoFields.WEEK_BASED_YEARS.isSupportedBy(ThaiBuddhistDate.now()),false);
+ assertEquals(IsoFields.QUARTER_YEARS.isSupportedBy(LocalDate.now()),true);
+ assertEquals(IsoFields.QUARTER_YEARS.isSupportedBy(ThaiBuddhistDate.now()),false);
+ }
+
@Test(dataProvider = "fields")
public void test_WBY_range(TemporalField weekField, TemporalField yearField) {
assertEquals(yearField.range(), ValueRange.of(Year.MIN_VALUE, Year.MAX_VALUE));